我需要获取要在数据库中删除的 id,但我无法通过这种方式获取 id 参数
@RequestMapping(value = {"/delete/search/","/delete/search"}, method = RequestMethod.DELETE)
@ResponseBody
public Integer deleteUser(@RequestBody Integer id_search) {
return id_search;
}
我收到此错误消息
"message": "JSON parse error: Can not deserialize instance of java.lang.Integer out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.Integer out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@1b77938; line: 1, column
最佳答案
也许您正在尝试从 Postman 客户端或类似这样的东西发送一个正文中包含 JSON 文本的请求:
{
"id_search":2
}
这不能被 Jackson 反序列化,因为这不是一个整数(它似乎是,但它不是)。来自 java.lang Integer 的 Integer 对象稍微复杂一些。
为了使您的 Postman 请求生效,只需简单地输入(不带花括号 { }
):
2
关于java - 在请求体上获取整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49192783/