HTTP Status 415 – Unsupported Media Type「建议收藏」

发布时间:2025-12-09 14:17:59 浏览次数:4

HTTP Status 415 – Unsupported Media Type解决方案和restful接口传参方式

  • 简述restful接口传参方式
    • GET/DELETE请求传参之url传参
    • GET/DELETE请求传参之url路径传参
    • POST/PUT请求Body体传参
  • POST/PUT请求获取参数

简述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参数)
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477