![](/img/trans.png)
[英]How to call ModelAndView method or getting reference to it in JSP page?
[英]call valang validator in MultiActionController ModelAndView method… possible? how?
這可能嗎? 我基本上使用MultiActionController類制作一個Spring CRUD Web應用程序,並希望我的表單得到驗證。 我之前使用過SimpleUrlController,valang完美運行。
根據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();
...
}
}
問候,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.