我正在学习Spring MVC,在过程中我遇到了这个问题:
// http://localhost:8080/todo-list/welcomeWithParam?user=Stefan
@GetMapping("welcomeWithParam")
public String welcome91(@RequestParam String user, Model model) {
model.addAttribute("helloThroughParam", demoService.getHelloMessage(user));
return "welcome-with-model";
}
// http://localhost:8080/todo-list/welcomeWithParam?user=Stefan&age=31
@GetMapping("welcomeWithParam")
public String welcome92(@RequestParam String user, @RequestParam int age, Model model) {
model.addAttribute("helloThroughParam", demoService.getHelloMessage(user));
model.addAttribute("age", age);
return "welcome-with-model";
}
我收到此错误:
引起原因:java.lang.IllegalStateException:不明确的映射。无法映射“demoController”方法
academy.learnprogramming.controller.DemoController#welcome92(字符串,整数,模型)
到 {GET [/welcomeWithParam]}:已经有 'demoController' bean 方法
academy.learnprogramming.controller.DemoController#welcome91(String, Model) 映射。
那么,Spring 告诉我我们不能有两个具有相同 URL 但参数数量/类型不同的 GET 映射?
如果我更改 @GetMapping("") 值之一的值,它就可以正常工作。
像这样的东西:
@RequestMapping(value = "/welcomeWithParam", params = "user")
public String welcome91(@RequestParam String user, Model model) {
// ...
}
@RequestMapping(value = "/welcomeWithParam", params = {"user","age"})
public ModelAndView welcome92(@RequestParam String user, @RequestParam int age, Model model) {
// ...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)