HTTP Status 415 – Unsupported Media Type

简述restful接口传参方式

GET/DELETE请求传参之url传参

    请求的url类似于
http://localhost:8080/springmvc/rest/passValue/param?name=root
    接收方法
/**
  * @RequestParam是默认接收参数的方式,可以省略
  * @RequestParam还可以接收form表单提交的数据
  */
@GetMapping("/param")
public String getByParam(@RequestParam String name)  
@DeleteMapping("/param")
public String deleteByParam(@RequestParam String name)

GET/DELETE请求传参之url路径传参

    请求的url类似于
http://localhost:8080/springmvc/rest/passValue/root
    接收方法
@GetMapping("/path/{name}")
public String getByPath(@PathVariable String name)
@DeleteMapping("/path/{name}")
public String deleteByPath(@PathVariable String name)

POST/PUT请求Body体传参

    请求的url类似于
http://localhost:8080/springmvc/rest/passValue/body
    请求设置 接收方法
@PostMapping("/body")
public String postByBody(@RequestBody User user) 
@PutMapping("/body")
public String putByBody(@RequestBody User user)

POST/PUT请求获取参数

    方法形参使用@RequestBody修饰(说明通过请求的body获取参数) 请求增加http头字段Content-Type:application/json(说明body体里面的参数是json格式) 工程引入jackson-annotations,jackson-core,jackson-databind包(解析body体的json参数)
经验分享 程序员 微信小程序 职场和发展