JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception i

代碼程序:java

 

@PostMapping("selectById")
@ResponseBody
public Result selectById(@RequestBody int id) {
   Result result =new Result();
   List<User> list = userService.selectById(id);
   if(list.size()==1){
   result.setCode("000");
   result.setMsg("success");
   result.setData(list);
}else if(list.size()==0){
      result.setCode("E01");
      result.setMsg("輸入的id找不到有效用戶");
      result.setData(null);
   }else {
      result.setCode("E02");
      result.setMsg("輸入的id找到大於1個有效用戶");
      result.setData(list);
   }
   return result;
}

  

 

 

 

請求內容:app

POST http://localhost:8080/user/selectByIdpost

POST data:
{
"id":300
}spa

返回信息:xml

{
: "timestamp":"2019-02-08T14:05:17.430+0000",
: "status":400,
: "error":"Bad Request",
: "message":"JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `int` out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]",
: "path":"/user/selectById"
}對象

 

用的是post的方式,傳的入參是int id, 不是一個對象。blog

須要改爲對象,而後獲取對象的idtoken

@ApiOperation(value = "根據ID查詢用戶的信息")
	@PostMapping("selectById")
	@ResponseBody
	public Result selectById(@RequestBody User user) {
		Result result =new Result();
		List<User> list = userService.selectById(user.getId());
		if(list.size()==1){
		result.setCode("000");
		result.setMsg("success");
		result.setData(list);
	}else if(list.size()==0){
			result.setCode("E01");
			result.setMsg("輸入的id找不到有效用戶");
			result.setData(null);
		}else {
			result.setCode("E02");
			result.setMsg("輸入的id找到大於1個有效用戶");
			result.setData(list);
		}
		return result;
	}
相關文章
相關標籤/搜索