考虑这个 Spring MVC Controller :
@Controller
@RequestMapping("/test*")
public class TestController {
@RequestMapping(method = RequestMethod.GET)
public void doStuff(Model model){
...
}
@RequestMapping(params = "myParam")
public void doStuff(@RequestParam("myParam") int myParam, Model model){
...
}
}
当我将其放入浏览器时:
mySite.com/test.html?myParam=1
我期待一个 AmbiguousHandlerMappingException 或其他东西,因为这两种方法似乎都与 URL 匹配。
但实际上第一个方法被调用了。有人知道为什么吗?
最佳答案
这闻起来像个 bug 。如果您将 method=GET 添加到第二个处理程序,它会按预期工作,因此这就是解决方法。
我已经就此提交了错误报告,希望它能得到解决。
关于java - Spring MVC 基于注释的 Controller 和@RequestMapping 的缩小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/885760/