欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'xxx' method

程序员文章站 2022-03-08 15:51:11
...

困扰了2天的一个问题,一般遇到这个异常是因为同一个控制器controller里面有两个requestmapping的映射路径重复了导致的,我遇到这个问题是因为自己的大意导致的:

错误 例子:

@RestController
public class WeiXinController extends BaseController {

    @RequestMapping(name = "wocaonima", method = RequestMethod.GET)
    public String wocaonima() {
        return "hello demo";
    }


    @RequestMapping(name = "nidayea", method = RequestMethod.GET)
    public void  nidayea () {
        System.out.println("hello nidayea");
        //return "hello nidayea";
    }

}

如果不认真看的话,感觉一点问题都没有,但是认真一看的话,发现是因为把value 写成了 name导致的

正确例子:

@RestController
public class WeiXinController extends BaseController {

    @RequestMapping(value = "wocaonima", method = RequestMethod.GET)
    public String wocaonima() {
        return "hello demo";
    }


    @RequestMapping(value = "nidayea", method = RequestMethod.GET)
    public void  nidayea () {
        System.out.println("hello nidayea");
        //return "hello nidayea";
    }

}

 

相关标签: Java报错