侧边栏壁纸
  • 累计撰写 2,058 篇文章
  • 累计创建 73 个标签
  • 累计收到 20 条评论

目 录CONTENT

文章目录

SpringBoot报错:Required URI template variable 'id' for method parameter type String is not present

大猿本猿
2022-04-24 / 21,210 阅读 / 0 字

错误描述

SpringBoot的Controller请求报错:Resolved

请求uri:http://127.0.0.1:16000/user?id=123

image

代码如下:

 /**
     * 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}名称一致。

image