Ambiguous handler methods mapped for'xxx'报错的解决办法
2022/8/15 23:28:00
本文主要是介绍Ambiguous handler methods mapped for'xxx'报错的解决办法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
这个报错的原因是我们的Controller中,有两个模棱两可的处理方法,这两个方法有歧义,无法分清谁是谁.因为Spring无法根据传参的类型自动匹配到可以处理的方法。比如下面这里,
@GetMapping("/{id}")和
@GetMapping("/{addr}")是冲突的,必须修改一下其中的一个url区分开来
package com.xzit.controller; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzit.entity.Emp; import com.xzit.service.EmpService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @RestController @RequestMapping("emp") @Api(tags = {"员工管理控制器"}) public class EmpController { @Resource private EmpService service; @ApiOperation("按给定的id显示员工信息") @GetMapping("/{id}") public Object selectId(@PathVariable Integer id){ Emp emp=service.selectId(id); return emp; } @ApiOperation("按给定地址查询员工信息") @GetMapping("/{addr}") public Object selectAddr(@PathVariable String addr){ List<Emp> empList=service.selectAddr(addr); return empList; } }
执行的报错信息,它分不清这两个方法。
正确的修改方式,我在selecAddr()方法随便加一个/userAddr的Url前缀:
package com.xzit.controller; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.xzit.entity.Emp; import com.xzit.service.EmpService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; @RestController @RequestMapping("emp") @Api(tags = {"员工管理控制器"}) public class EmpController { @Resource private EmpService service; @ApiOperation("按给定的id显示员工信息") @GetMapping("/{id}") public Object selectId(@PathVariable Integer id){ Emp emp=service.selectId(id); return emp; } @ApiOperation("按给定地址查询员工信息") @GetMapping("/userAddr/{addr}") public Object selectAddr(@PathVariable String addr){ List<Emp> empList=service.selectAddr(addr); return empList; } }
重启服务,报错解决,可以正确查询出数据了:
参考文章:
https://blog.csdn.net/syc000666/article/details/94978731
这篇关于Ambiguous handler methods mapped for'xxx'报错的解决办法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?
- 2024-05-09企业src漏洞挖掘-有意思的命令执行