错误描述
SpringBoot的Controller请求报错:Resolved 。
请求uri:http://127.0.0.1:16000/user?id=123
代码如下:
/**
* GET 返回单个用户信息
* */
@RequestMapping(method = RequestMethod.GET,value = "/user")
@ResponseBody
public Object user(@PathVariable("id") String id) throws Exception {
List<User> userList = userService.get(id);
return userList;
}
引起原因
参数问题,@PathVariable("id") String id有id,但是RequestMapping中没有id,造成不匹配。
解决方案
修改RequestMapping中的value = "/user"为/user/{id},参数的id必须和你GetMapping里面的{id}名称一致。