服务报错:Required request body is missing

完整异常

org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing

问题原因

1、Post请求接口,使用了@RequestBody注解,但传参为null,导致请求体为空,抛出上述异常

解决方法:

至少得传一个空的请求体{},即便里面什么也没有。

如果真要传null,请把@RequestBody 改为@RequestBody (required=false)

加上此属性代表参数类型支持为null,没加之前默认是不支持的

2、Get请求接口,却使用了@RequestBody注解

解决方法:

请把Get请求换成Post请求,Get请求是不支持@RequestBody注解的

3、接口和请求不对应,Get接口用Post请求访问,Post接口用Get请求访问

解决方法:

请把请求方式和接口类型对应上,Get和Post分清楚

猜你喜欢

转载自blog.csdn.net/weixin_42559574/article/details/108705776
今日推荐