@Controller 注解类中方法使用 @RequestBody 注解接收表单提交的参数抛出异常。

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 注解代替两种解决方式。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值