【发布时间】:2013-07-30 16:51:34
【问题描述】:
是否可以在单个控制器中拥有多个 initBinder 方法?每个 InitBinder() (参见代码)依赖于一个唯一的请求处理程序,例如在 url: "/update/account" 上调用 initBinder() 并在 "update/account/pass" 上调用 initBinderOne()?
我希望所有更新都使用一个控制器而不是多个。请指教。
@Controller
@RequestMapping(value="/uodate/account")
public class UpdateController {
@RequestMapping(method=RequestMethod.GET)
public String updateAccount(@ModelAttribute("account") Account account...){
..
}
@RequestMapping(method=RequestMethod.POST)
public String update(@Valid Account account...){
...
}
@RequestMapping(value="/pass", method=RequestMethod.GET)
public String updatePass(@ModelAttribute("account") Account account...){
...
}
@RequestMapping(value="/pass",method=RequestMethod.POST)
public String updatePass(@Valid Account account...){
...
}
@InitBinder("account")
public void initBinder(WebDataBinder binder){
binder.setValidator(validateAccount);
binder.setAllowedFields(new String[]{"accountId","accountname","firstName",
"lastName","address"});
}
@InitBinder("account")
public void initBinderOne(WebDataBinder binder){
binder.setValidator(validatePassword);
binder.setAllowedFields(new String[]{"accountId","password});
}
【问题讨论】:
标签: spring model-view-controller spring-mvc spring-mvc-initbinders