显然,杰克逊无法将传递的JSON反序列化为
Integer。如果您坚持通过请求正文发送 用户
的JSON表示形式,则应将封装
userId在另一个bean中,如下所示:
public class User { private Integer userId; // getters and setters}然后使用该bean作为您的处理程序方法参数:
@RequestMapping(...)public @ResponseBody Record getRecord(@RequestBody User user) { ... }如果您不喜欢创建另一个bean的开销,则可以将
userIdas作为 路径变量的 一部分传递,例如
/getuser/15。为了做到这一点:
@RequestMapping(value = "/getuser/{userId}", method = POST, produces = "application/json")public @ResponseBody Record getRecord(@PathVariable Integer userId) { ... }由于您不再在请求正文中发送JSON,因此应删除该
consumes属性。



