答案 0 :(得分:0)
根据MultiActionControlller API
考虑在控制器方法中直接使用ServletRequestDataBinder,INSTEAD OF依赖于声明的命令参数。这样可以完全控制整个活页夹的设置和使用,包括验证者的调用以及绑定/验证错误的后续评估。
所以你可以使用
public class AddMultiActionController extends MultiActionController {
public AddMultiActionController() {
// Set up Valang according to your business requirement
// You can use xml settings instead
setValidators(new Validator [] {new CommandValidator(), new AnotherCommandValidator()});
}
public ModelAndView addCommand(HttpServletRequest request, HttpServletResponse response) throws Exception {
Command command = new Command();
// createBinder is a MultiActionController method
ServletRequestDataBinder binder = createBinder(request, command);
// Sets up any custom editor if necessary
binder.registerCustomEditor(...);
binder.bind(command);
return (!(binder.getErrors().hasErrors())) ? new ModelAndView("success") : new ModelAndView("failure");
}
// similar approach as shown above
public ModelAndView addAnotherCommand(HttpServletRequest request, HttpServletResponse response) throws Exception {
AnotherCommand anotherCommand = new AnotherCommand();
...
}
}
的问候,