How to define multiple initBinders

给你一囗甜甜゛ 提交于 2019-12-04 12:09:12

Spring does not support attaching multiple validators to a single command. You can, however, define multiple @InitBinder methods for different commands. For example, you could put the following in a single controller and validate your user1 and user2 parameters:

@InitBinder("user1")
protected void initUser1Binder(WebDataBinder binder) {
    binder.setValidator(new User1Validator());
}

@InitBinder("user2")
protected void initUser2Binder(WebDataBinder binder) {
    binder.setValidator(new User2Validator());
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!