@requestBody作用和注意

今天联系Angular时用$http 往服务器传了 {role_id:$scope.role} 的json字符串,

在服务器端用@requestBody Integer role_id 接受时报了400 BadRequst错误 ,

@RequestBody作用:

@RequestBody注解用于读取http请求的内容(字符串),通过springmvc提供的HttpMessageConverter接口将读到的内容(json数据)转换为java对象并绑定到Controller方法的参数上。

所以应该是在绑定参数时发生错误而报了400错误。

后来我用封装了 Integer role_id 属性的对象来接收数据,结果成功!

 

猜你喜欢

转载自blog.csdn.net/steppppup/article/details/81326993