我有这个控制器,但我不知道为什么当我访问/accounts/manageaccount.do时出现错误
public class ManageAccountController {
public static final Logger LOGGER = Logger.getLogger (ManageAccountController.class);
/**
*
* @param request the http servlet request.
* @param model the spring model.
*
*/
@RequestMapping(value = "/accounts/manageaccount.do", method = RequestMethod.GET)
public String showForm( @ModelAttribute("dataAccountCommand") final DataAccountCommand dataAccountCommand,
HttpServletRequest request,
BindingResult result,
Model model,
Locale locale) {
return "SHOW_VIEW";
}
异常:org.springframework.web.bind.annotation.support.HandlerMethodInvocationException:无法调用处理程序方法[public java.lang.String fr.telecom.controller.accounts.ManageAccountController.showForm(fr.telecom.domain.formBeans) .DataAccountCommand,javax.servlet.http.HttpServletRequest,org.springframework.validation.BindingResult,org.springframework.ui.Model,java.util.Locale中)];嵌套异常是java.lang.IllegalStateException:声明的Errors / BindingResult参数没有先前的模型属性。检查处理程序方法签名!
答案 0 :(得分:5)
您需要将BindingResult
参数直接放在使用@ModelAttribute
注释的参数之后。所以将您的签名更改为:
@RequestMapping(value = "/accounts/manageaccount.do", method = RequestMethod.GET)
public String showForm(
@ModelAttribute("dataAccountCommand") final DataAccountCommand dataAccountCommand,
BindingResult result, // moved up!
HttpServletRequest request,
Model model,
Locale locale) {
return "SHOW_VIEW";
}
应该这样做。
另请参阅:http://viralpatel.net/blogs/errorsbindingresult-argument-declared-without-preceding-model-attribute/