HttpMessageNotReadableException: Required request body is missing(2022-04-18)

导出excel功能

@ApiOperation("导出Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletRequest request, HttpServletResponse response){

使用get请求,如果传100个ids,浏览器路径有长度限制

HttpMessageNotReadableException: Required request body is missing(2022-04-18)_第1张图片

修改为使用body接参数

@ApiOperation("导出Excel")
@GetMapping("/exportExcel")
public ActionResult exportExcel(@RequestBody ControlsExcelVO controlsExcelVO, HttpServletResponse response) {

使用 postman 进行测试

HttpMessageNotReadableException: Required request body is missing(2022-04-18)_第2张图片

后端报错信息:

请求路径:xxx/Controls/exportExcel
2022-04-18 16:57:54.967  WARN 65872 --- [nio-7774-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver :

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

public portal.base.ActionResult portal.system.controller.ControlsController.exportExcel(

portal.system.model.controls.ControlsExcelVO,javax.servlet.http.HttpServletResponse)]

请求路径:/error

解决:把参数类型 Text 改为 JSON

HttpMessageNotReadableException: Required request body is missing(2022-04-18)_第3张图片

参考博文:

HttpMessageNotReadableException: Required request body is missing异常处理_hacker_LeeFei的博客-CSDN博客1.异常示例2.分析原因2.1 接口参数用@RequestBody时,前端需用json格式传输2.2 postman参数json格式设置3.注意参数保持格式一致^ - ^https://blog.csdn.net/hacker_Lees/article/details/95358639

你可能感兴趣的:(错误累积(错题本),java,后端)