Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotReadableException:
@Controller 注解类中,方法使用 @RequestBody 注解接收表单提交的参数抛出异常。
@RequestMapping(value = "/dept/add",method = RequestMethod.GET)
public boolean add(@RequestBody Dept dept){
return deptService.add(dept);
}
界面信息
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Jun 30 21:31:41 CST 2019
There was an unexpected error (type=Bad Request, status=400).
Bad Request
服务器爆出异常
Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean com.atguigu.springcloud.controller.DeptController.add(com.atguigu.springcloud.entities.Dept)
原因
原来 @RequestBody 注解常用来处理 content-type 是 application/json 编码的内容,而不能用来处理 application/x-www-form-urlcoded 编码的内容。这里可以选择不添加注解或者使用 @ModelAttribute 注解代替两种解决方式。