org.springframework.http.converter.HttpMessageNotReadableException:


后台报错信息:

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public ins.framework.web.ApiResponse com.sinosoft.agency.insurer.api.InsurerApi.query(com.sinosoft.agency.insurer.vo.SabGInsurerVo)

前台报错信息:

error:"Bad Request"
exception:"org.springframework.http.converter.HttpMessageNotReadableException"
message:"Required request body is missing: public ins.framework.web.ApiResponse com.sinosoft.agency.insurer.api.InsurerApi.query(com.sinosoft.agency.insurer.vo.SabGInsurerVo)"
path:"/standards/cooperativePartner/query"
status:400
timestamp:1544684616270

原因:
报错时:后台代码

	@RequestMapping(value="/query",method = RequestMethod.POST)
	@CrossOrigin
	public ApiResponse query(@RequestBody SabGInsurerVo vo){
		ResultPage<SabGInsurerVo> result = insurerService.querySUBByUpperComCode(vo);
		return new ApiResponse(result);
	}

改错后的代码:去掉@RequestBody的注解

	@RequestMapping(value="/query",method = RequestMethod.POST)
	@CrossOrigin
	public ApiResponse query(SabGInsurerVo vo){
		ResultPage<SabGInsurerVo> result = insurerService.querySUBByUpperComCode(vo);
		return new ApiResponse(result);
	}

刚开始我以为是数据库的字段和VO实体类的字段不一致导致的,一致在纠结我在实体类中添加的新的变量跟数据库的查询有什么关系,拿着问题在百度爬爬呗,就看到有提示:注解可能导致的,忽然看到自己的传入的对象上面有注解,我就把注解去掉,试试结果就通了,数据正常传入前端并正常显示。

@requestBody这个标签在post 、put 方法中用于接收json格式的数据

@requestParam这个标签接收的是key-value形式的参数。

发生这个错误有很大程度上是因为接值时候用的标签不对,不应该用@requestBody标签。

猜你喜欢

转载自blog.csdn.net/weixin_42571463/article/details/84990086