spring boot 2.2.6 以上版本 错误:HttpMessageNotReadableException: Required request body is missing

项目升级使用spring boot 2.2.13 ,在使用postman测试接口时报错:HttpMessageNotReadableException: Required request body is missing

在自己的controller的接口里接收不到body数据, 示例代码如下:

    @PostMapping(value = "/java/test/findByPage")
    public Object findByPage(@RequestBody FilterVo filterVo) {
        try {
            logger.info(" findByPage  filterVo{}", filterVo);
           return "";
        } catch (Exception e) {
            logger.error("------", e);
            return e;
        }
    }

造成这个错误的原因是在请求的头部的 Content-Type 参数造成的。

postman 的自动设置这个参数为:"application/json;charset=UTF-8"  ,即使你设置成  "application/json",在请求时也会变成前面的那个。所以spring boot 并没有识别,没有给转换。

解决办法:

 "Content-Type"  设置成 "application/json",请求接口正常。

   至于postman[8.0.6]如何设置不自动增加"chartset=UTF-8",还请高手留言!

另外为什么提到spring boot的版本,因为在2.2.6的时候并没有发现这个问题。至于在哪个小版本中改成这样的,本人未知。

猜你喜欢

转载自blog.csdn.net/saperliu/article/details/114524448