Ambiguous handler methods mapped 模棱两可的方法
程序员文章站
2022-03-01 13:37:26
...
方法重载出了问题,这两个方法都会出错
@RestController
@RequestMapping("/anonym/userinformation/RegisteUserInfo")
public class UnUsUserController extends BaseController
{
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id)
{
return AjaxResult.success(usUserService.selectUsUserById(id));
}
/**
* 根据email获取用户信息
*/
@GetMapping(value = "/{email}")
public AjaxResult getUsUserByEmail(@PathVariable("email") String email)
{
return AjaxResult.success(usUserService.selectUsUserByEmail(email));
}
}
使用rest编程风格时,可以直接将变量值放入到url中,传递到后台,后台自动识别对应的方法,方便很多。
但这个错误说明,spring无法根据传参的类型自动匹配处理的方法,注意的是方法重载不可以根据参数类型和名称进行识别。
因为从前台传来的url长这样的:/anonym/userinformation/RegisteUserInfo/[email protected],只传入了一个参数,没给参数名。
所以修改其中一个路径
/**
* 根据email获取用户信息
*/
@GetMapping(value = "/email/{email}")
public AjaxResult getUsUserByEmail(@PathVariable("email") String email)
{
return AjaxResult.success(usUserService.selectUsUserByEmail(email));
}
推荐阅读
-
java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path
-
swagger 报错 Ambiguous handler methods mapped for ‘/v3/api-docs/‘
-
报错处理:“Ambiguous handler methods mapped for ...”
-
Ambiguous handler methods mapped for HTTP path
-
Ambiguous handler methods mapped 模棱两可的方法
-
Ambiguous handler methods mapped for 'xxx'的解决办法
-
java.lang.IllegalStateException: Ambiguous handler methods mapped for ‘/emp/lisi‘: {public com.weiji