【发布时间】:2016-03-06 12:41:15
【问题描述】:
我有这个 POST 方法,它只验证表单并在表单被验证时返回确认视图,如果任何字段错误,我想发送回注册屏幕。在这种情况下,如果 BindingResult 对象有错误,系统会将用户返回到表单屏幕,但显示的 URL 是“/registerConfirmation”,这应该只是在表单没有错误的情况下。
@RequestMapping(value="/registerConfirmation", method = RequestMethod.POST)
public ModelAndView confirmRegister(@Valid @ModelAttribute("form") RegistrationForm form, BindingResult result){
logger.info("Sending registration data");
ModelAndView modelAndView = new ModelAndView();
if(result.hasErrors()){
modelAndView.setViewName("register");
modelAndView.addObject("form", form);
return modelAndView;
}
//more code here
return modelAndView;
}
我不知道我错过了什么,因为我在许多其他帖子中看到过这样的方法。有什么帮助吗??
非常感谢!!!
【问题讨论】:
标签: java spring-mvc http-post thymeleaf