代码程序:

@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;
}

  

请求内容:

POST http://localhost:8080/user/selectById

POST data:
{
"id":300
}

返回信息:

{
: "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, 不是一个对象。

需要改成对象,然后获取对象的id

@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;
}

  

JSON parse error: Cannot deserialize instance of `int` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc的更多相关文章

  1. JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of j

    异常信息如下: JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token ...

  2. SpringMVC接口测试异常:Can not deserialize instance of int out of START_OBJECT token

    之前使用springmvc搭建了restful风格的接口服务,在使用mockmvc进行集成测试的时候出现了异常:Can not deserialize instance of int out of S ...

  3. HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite

    org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite r ...

  4. 记一次接口调试错误: {"timestamp":"2019-09-11T03:04:30.036+0000","status":500,"error":"Internal Server Error","message":"Could not write JSON: Object is null; nested exception is com.fasterxml.jackson

    接口测试中用postman测试返回是正常的,但是使用其他人去调用就出错了,找了半天,才想起来使用了nginx,用于端口的代理转发.然后根据错误信息发现json格式的某个字段为null,结合日志中的报文 ...

  5. JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String

    在使用Postman测试Spring Boot项目接口时,接口返回JSON parse error: Cannot deserialize value of type `java.time.Local ...

  6. JSON parse error: Cannot deserialize value of type `java.util.Date` from String

    DateTimePicker + @DateTimeFormat("yyyy-MM-dd HH:mm:ss")日期格式转换异常 最近在做的一个项目使用的日期格式是yyyy-MM-d ...

  7. jackson json转实体对象 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

    Jackson反序列化错误:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field的解 ...

  8. JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value

    问题原因所在:前端Vue传输的数据字段类型和后端实体类字段不一致. 我的实体类字段是int类型.前端传输的数据是布尔类型. 文章目录 1.后端方法 2.实体类字段 2.前端传输的数据 1.后端方法 @ ...

  9. jackson json转实体 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException

    jackson 2.2.2 由于vo中缺少json的某个字段属性引起 2种解决方法 1:vo中添加注解@JsonIgnoreProperties(ignoreUnknown = true) 2.  m ...

随机推荐

  1. input file accept类型

    Valid Accept Types: For CSV files (.csv), use: <input type="file" accept=".csv&quo ...

  2. 一位前辈的博客,收获颇丰,包括Android、Java、linux、前端、大数据、网络安全等等

    https://www.cnblogs.com/lr393993507/   魔流剑

  3. 使用Wisdom RESTClient进行自动化测试,如何取消对返回的body内容的校验?对排除的JSON属性字段不做校验?

    使用 Wisdom RESTClient 进行自动化测试 REST API,默认是对返回HTTP状态码和body内容都进行严格匹配和校验. (1). 如果每次触发API返回的body内容是动态变化的, ...

  4. Prometheus监控学习笔记之初识PromQL

    0x00 概述 Prometheus 提供了一种功能表达式语言 PromQL,允许用户实时选择和汇聚时间序列数据.表达式的结果可以在浏览器中显示为图形,也可以显示为表格数据,或者由外部系统通过 HTT ...

  5. fjwc2019 D2T3 排序(堆)

    #183. 「2019冬令营提高组」排序 贴一段ppt 考虑模拟出这个算法进行k轮(即外层的i循环到k)时的序列,之后再暴力模拟零散的步. 考虑这个算法在01序列上的表现,k轮后实际上就是将最开始的不 ...

  6. paymob浙江正和

    #region 上海 ZH //else if (order.SP.Contains("上海") && order.Area.Contains("移动&q ...

  7. 02: pycharm远程linux开发和调试代码

    1.1 配置远程linux主机信息 参考博客:https://www.cnblogs.com/lei0213/p/7898301.html 1) 选择Tools--Deployment--Config ...

  8. k8s device plugin

    基本概念入门: Device Manager Proposal Device plugin offical Doc(中文) device-plugins offical Doc(En) Go thro ...

  9. 做了一道cf水题

    被一道cf水题卡了半天的时间,主要原因时自己不熟悉c++stl库的函数,本来一个可以用库解决的问题,我用c语言模拟了那个函数半天,结果还超时了. 题意大概就是,给定n个数,查询k次,每次查询过后,输出 ...

  10. shell脚本中如何实现scp传输?

    示例脚本如下: #! /bin/sh expect -c " spawn scp -r /home/jello/jello.txt jello@110.110.110.110:/home/j ...