如果想使用全局范围的自定义编辑器,可以使用WebBindingInitializer接口,并在该类中注册自定义编译器。
public class DateBindingInitializer implements WebBindingInitializer {
@Override
public void initBinder(WebDataBinder binder, WebRequest request) {
// 注册自定义编辑器
binder.registerCustomEditor(Date.class, new DateEditor());
}
}
DateEditor在上篇blog中已定义。这时就不需要在Controller中使用@InitBinder。但是需要在springmvc-config.xml中配置
<!-- 通过AnnotationMethodHandlerAdapter装配自定义编辑器 -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.fkjava.binding.DateBindingInitializer" />
</property>
</bean>
如果你在spring中使用了3中数据转换方法,那么他们的优先顺序
- 1,通过@InitBinder装配的自定义编辑器
- 2,通过ConversionService装配的自定义转换器
- 3,通过WebBindingInitializer接口装配的全局自定义编辑器。
写完这3片blog后,其实我更好奇是其后面隐藏的spring使用数据转换器的流程,这个在稍后的blog中介绍。
转载于:https://www.cnblogs.com/arax/p/8551911.html
最后
以上就是震动荔枝最近收集整理的关于Spring数据转换(三)-- WebBindingInitializer的全部内容,更多相关Spring数据转换(三)--内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复