SpringBoot与HTTP请求

2019-08-14  本文已影响0人  GambitP_P
  1. GET(查询,参数在URL后拼接)

  2. DELETE(删除,参数在URL后拼接)

  3. PUT(更新,参数在URL后拼接)

  4. POST(保存,参数放入body中,格式使用application/x-www-form-urlencoded)

  5. Spring Boot相关注解

//包含在path中提交参数
@RequestMapping(path = "/{id}", method = RequestMethod.GET)
public String getStore(@PathVariable String id) {}

//可代替@RequestMapping(method = RequestMethod.GET)
@GetMapping 

//可代替@RequestMapping(method = RequestMethod.POST)
@PostMapping

//可代替@RequestMapping(method = RequestMethod.PUT)
@PutMapping 

// 可代替@RequestMapping(method = RequestMethod.DELETE)
@DeleteMapping
​
//可以设置默认值,比如分页 
@RequestParam(value = "name", required = true)

//请求体映射实体类,需要指定http头的content-type为application/json,charset=utf-8
@RequestBody
​
//请求头,比如鉴权
@RequestHeader("access_token") String accessToken
​
//使用自动注入获取参数
HttpServletRequest request
上一篇 下一篇

猜你喜欢

热点阅读