java.lang.IllegalStateException: Ambiguous handler methods mapped for ‘/user/1‘: {public com.woniu.b

 错误代码:

 @GetMapping(value = "/{id}")
    public Result queryUserById(@PathVariable Long id) {

        Result result = new Result();
        User user = iUserService.getById(id);

        // 根据查询结果对result进行设置
        if (user != null) {
            result.setCode(Code.GET_OK);
            result.setMsg("成功");
            result.setData(user);

        } else {
            result.setCode(Code.GET_ERR);
            result.setMsg("失败");
        }

        return result;
    }

    @GetMapping
    public Result queryAllUsers() {
        Result result = new Result();

        List<User> users = iUserService.list(null);
        if (users != null && users.size() > 0) {
            result.setCode(Code.GET_OK);
            result.setMsg("成功");
            result.setData(users);

        } else {
            result.setCode(Code.GET_ERR);
            result.setMsg("失败");
        }
        System.out.println("users = " + users);
        return result;
    }

    @GetMapping("/{current}")
    public Result findUserByPage(@PathVariable Integer current){

        IPage<User> p = new Page<>(current,2);

        // page中有 查询的结果
        //
        IPage<User> page = iUserService.page(p);

        //分页展示的数据
        List<User> list = page.getRecords();
        //分页的总数 (多少页)
        Long pages = page.getPages();

        Result result = new Result();

        result.setCode(100);
        result.setMsg("成功");

        //封装 分页的数据
        PageBean<User> pageBean = new PageBean<>();
        pageBean.setList(list);
        pageBean.setPages(pages.intValue());

        result.setData(pageBean);

        return result;
    }

错误原因:

写了两个@GetMapping(value = "/{id}"), @GetMapping("/{current}")后端无法对这两个进行识别,因为在后端看来这两个东西都是"/数据"的格式,因此无法识别出来。

总结:

不要以人的思维去看程序,人可能能识别形参的区别,但是机器却不能识别。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小海海不怕困难

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值