代码程序:

@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. Django框架----外键关联

    app/models.py中: 创建班级表 class classes(models.Model): id = models.AutoField(primary_key=True) name = mo ...

  2. airtest 记录

    from airtest.core.api import * # 通过ADB连接本地Android设备 connect_device("Android:///") #安装待测软件a ...

  3. Redis Desktop Manager 利用ssh连接 Redis

    需开启6379端口,如果不设置密码,就忽略1,2步骤 第一步: 第二步: 第三步: 第四步: 第五步:

  4. Spring学习笔记2:Spring HelloWorld

    1:IntelliJ新建Maven工程 2:pom文件加入Spring依赖 <project xmlns="http://maven.apache.org/POM/4.0.0" ...

  5. 【题解】Luogu P2146 [NOI2015]软件包管理器

    题面:https://www.luogu.org/problemnew/lists?name=2146 这道题要用树链剖分,我博客里有对树链剖分的详细介绍 这道题就是树链剖分的模板,详细解释见程序. ...

  6. 利用shell脚本通过ssh绕过输入密码直接登录主机

    shell #!/usr/bin/expect spawn ssh root@192.168.137.141 expect "*password:" send "lizh ...

  7. [c/c++] programming之路(9)、运算优先级

    一.运算优先级 二.条件运算符(表达式1?表达式2:表达式3) 当式1正确时,取式2的值:否则,取式3的值 三.格式字符 #include<stdio.h> #include<std ...

  8. topcoder srm 692 div1 -23

    1.给定一个带权有向图.选出一些边满足使得任意两点可相互到达的前提下使得选出的边的权值的最大最小差值最小. 思路:二分答案,然后枚举权值的范围判断是否可行. #include <stdio.h& ...

  9. 使用vs code搭建C开发环境

    关于搭建vscode的开发环境来开发c网上已经有很多类似的贴子,但是几乎都是直接给出tasks.json和launch.json文件,并未说明这两个文件的作用以及如何配置.这里面向纯小白着重说明下(1 ...

  10. bzoj 1251: 序列终结者 平衡树,fhqtreap

    链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1251 思路 好简单的模板题 不过还是wrong了好几发 叶子节点要注意下,不能使用 遇到就不 ...