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

posted on 2016-07-01 17:14  路人甲乙丙丁张三  阅读(1066)  评论(0编辑  收藏  举报