赞
踩
下面方法是post方法,但是参数既有json对象,又有链接携带参数
@PostMapping("/xxxx") //post请求
//@RequestBody 表示传入的参数是一个json对象
//@RequestParam 表示传入的参数是一个链接中携带的参数
public xxxx find(@RequestBody String id , @RequestParam String name){
//从传入的json对象中获取单个参数的value
Integer id = Integer.parseInt(JSON.parseObject(id).get("id").toString().trim());
}
在postman测试中,既要设置param,又要设置body中的json数据
如果postman传入的json,但是方法接收的是@RequestParam就会报错
“message”: “JSON parse error: Cannot deserialize instance of java.lang.Integer out of START_OBJECT token;
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance
of java.lang.Integer out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]”
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。