java.lang.IllegalStateException: Ambiguous handler methods mapped for ‘/emp/lisi‘: {public com.weiji
2020-07-07 14:46
483 查看
springboot 客户端访问controller时访问路径问题
@GetMapping("/emp/{id}") public Employee getEmp(@PathVariable("id") Integer id){ Employee emp = service.getEmpById(id); return emp; }
方法一:根据id查询员工
@GetMapping("emp/{name}") public Employee getEmpByName(@PathVariable("name") String name){ return service.getEmpByName(name); }
方法二:根据name查询员工
错误原因:
可以看到是类型转换异常,主要是因为两个方法访问路径只有参数不同,在controller方法接收请求时没办法区分,不知道用哪个方法处理,这时当String类型注入Integer类型时就会发生类型转换异常,所以可以多加一层访问路径区分请求
@GetMapping("emp/lastName/{name}") public Employee getEmpByName(@PathVariable("name") String name){ return service.getEmpByName(name); }
相关文章推荐
- SpringMVC 报错java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path
- Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/runyu/a/res/resource': {public
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.sojs
- Ambiguous handler methods mapped for HTTP path
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.dao
- Ambiguous handler methods mapped for HTTP path
- Ambiguous handler methods mapped for HTTP path。。这是映射重复出现的错误!出现
- jAmbiguous @ExceptionHandler method mapped for [class java.lang.Throwable]:
- Ambiguous handler methods mapped for HTTP path
- 映射重复导致的错误:Ambiguous handler methods mapped for HTTP path
- java.lang.IllegalArgumentException: Mapped Statements collection already contains value for
- java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for study.my
- java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver Eclipse3.1 数据库连接测试程序(SQL Server 2000 Driver for JDBC Service Pack 3 安装测试)
- java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType
- 异常:failed for object com.sdu.crm.pojo.Customer@136a986 [java.lang.NullPointerException]
- 解决java.lang.RuntimeException: mapped-name is required for hibernateTemplate1 of deployment MIS.war
- Java 中 modifer 'public' is reduntant for interface methods
- java.lang.UnsatisfiedLinkError: No implementation found for int com.xxx.xx中的couldn’t find “XX.so”或loadLibrary("xxx")失败
- java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger for JUnit test case for Java mail
- java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id “null“ at org.spr