关于spring-mvc的InitBinder注解的参数

来源:互联网 发布:2015网络大电影排行榜 编辑:程序博客网 时间:2024/06/12 00:09
通过Spring-mvc的@InitBinder注释的方法可以对WebDataBinder做一些初始化操作。
比如设置Validator。
我一直在想能不能为每个Request或者每个Action方法单独设置Validator。
也就是说Controller里有多个被@InitBinder标注的方法。 在不同的Action时被分别调用。

我注意到了@InitBinder的value参数,

api docs里是这样描述的:
The names of command/form attributes and/or request parameters that this init-binder method is supposed to apply to.

Default is to apply to all command/form attributes and all request parameters processed by the annotated handler class. Specifying model attribute names or request parameter names here restricts the init-binder method to those specific attributes/parameters, with different init-binder methods typically applying to different groups of attributes or parameters.

是乎是可以针对不同的Form对象或命令调用不同的InitBinder方法。

于是我写了下面的Controller试了一下

原创粉丝点击