Ambiguous handler methods mapped for HTTP path

Posted 吴明杰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ambiguous handler methods mapped for HTTP path相关的知识,希望对你有一定的参考价值。

一、问题:映射重复导致的错误 

java代码如下:

 

  @RequestMapping(value = "/info/{remove}/{id}", method = RequestMethod.GET)
    public String removeNewsById(@PathVariable("id") long id) {
@RequestMapping(value = "/info/{fav}/{id}", method = RequestMethod.GET)
    public String increaseFavoriteById(@PathVariable("id") long id) {

报以下错误:

 

 

message Request processing failed; nested exception is java.lang.IllegalStateException: 
Ambiguous handler methods mapped for HTTP path ‘http://localhost:8080/zc-beauty2/news/info/fav/6‘:
 {public java.lang.String com.zc.beauty.controller.NewsController.removeNewsById(long), 
public java.lang.String com.zc.beauty.controller.NewsController.increaseFavoriteById(long)}


我的意图是分别访问 /info/remove/id 和/info/fav/id

 

上述写法有问题:用{} 包裹起来的变量好像会被模糊化:

/info/{remove}/{id}  和 

/info/{fav}/{id}

的映射是重复的

 

二、解决办法:

写成如下格式:

/info/remove/{id}

对于确定的路径参数不要加{}

问题解决。

以上就介绍了Ambiguous handler methods mapped for HTTP path,包括了方面的内容,希望对JSP教程有兴趣的朋友有所帮助。

转自http://www.codes51.com/article/detail_161369.html

以上是关于Ambiguous handler methods mapped for HTTP path的主要内容,如果未能解决你的问题,请参考以下文章

异常:java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path '/app/userInf

Ambiguous mapping found. Cannot map 'competeController' bean method

Ambiguous mapping. Cannot map *** method 报错解决

Ambiguous mapping. Cannot map *** method 报错解决

记录:Ambiguous mapping. Cannot map ‘eduTeacherController‘ method解决方案

记录:Ambiguous mapping. Cannot map ‘eduTeacherController‘ method解决方案