我正在尝试使控制器对GET和POST请求使用相同的URI。但是我遇到了以下错误。
Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/boards/forgotPassword/recoverForm':
据我所知,这不应该发生,因为一个使用GET请求,另一个使用POST。如果我错了,请纠正我。控制器的详细信息如下。
@Controller
@RequestMapping(value = "/forgotPassword", method = RequestMethod.GET)
public class PasswordResetController {
@ModelAttribute("userEmail")
public UserEmail makeUserEmailDTO () {
UserEmail userEmail = new UserEmail();
return userEmail;
}
//@RequestMapping(value = "/recoverForm", method = RequestMethod.GET) --> same error
@GetMapping("/recoverForm")
public String getRecoverForm () {
return "_recoverForm";
}
//@RequestMapping(value = "/recoverForm", method = RequestMethod.POST) --> same error
@PostMapping("/recoverForm")
public String sendRecoverEmail (@ModelAttribute("userEmail") @Valid UserEmail userEmail, BindingResult result) {
System.out.println(userEmail.getEmail());
return "_temp";
}
}
答案 0 :(得分:1)
从第3行中删除“方法= RequestMethod.GET”。此属性将GET定义为上述所有方法。