我拆过的坑cycx

查询一下!

Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body

解决方案如下:

解析:在后台方法参数上添加@RequestBody时,将请求参数封装成User对象时,需要JSON(application/json)格式解决:在Postman中如下设置即可正常访问,便于调试。



否则应该用:@RequestParam



(1)不加@RequestParam前端的参数名需要和后端控制器的变量名保持一致才能生效


(2)不加@RequestParam参数为非必传,加@RequestParam写法参数为必传。但@RequestParam可以通过@RequestParam(required = false)设置为非必传。


(3)@RequestParam可以通过@RequestParam(“userId”)或者@RequestParam(value = “userId”)指定传入的参数名。


(4)@RequestParam可以通过@RequestParam(defaultValue = “0”)指定参数默认值


(5)如果接口除了前端调用还有后端RPC调用,则不能省略@RequestParam,否则RPC会找不到参数报错


(6)访问时:


不加@RequestParam注解:url可带参数也可不带参数,输入 localhost:8080/list1 以及 localhost:8080/list1?userId=xxx 方法都能执行

加@RequestParam注解:url必须带有参数。也就是说你直接输入localhost:8080/list2 会报错,不会执行方法。只能输入localhost:8080/list2?userId=xxx 才能执行相应的方法

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.7.3

Copyright Your WebSite.Some Rights Reserved.