异常
http://localhost:8000/users/{id}
“message”: “Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Long’; nested exception is java.lang.NumberFormatException: For input string: \”{id}\””,
解决
//没有写paramType = “path” 会提示类型转换String convert to Long错误。
如下在ApiImplicitParam 中加上请求参数paramType=”path”即可
@ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType="path", dataType = "Long"),
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
})
@RequestMapping(value="/{id}", method=RequestMethod.PUT)
public String putUser(@PathVariable Long id, @RequestBody User user) {
User u = users.get(id);
u.setName(user.getName());
u.setAge(user.getAge());
users.put(id, u);
return "success";
}
版权声明:本文为knockheart原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。