zoukankan      html  css  js  c++  java
  • Spring数据转换(三)-- WebBindingInitializer

    如果想使用全局范围的自定义编辑器,可以使用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中介绍。

    I am chris, and what about you?
  • 相关阅读:
    Android 面试题汇总
    Android中Listview展示及其优化好处
    手机APP创建桌面快捷方式
    popupwindow展示
    showSetPwdDialog--自定义对话框
    android 四大组件之---Service
    会话技术( Cookie ,Session)
    Request 和 Response 原理
    Servlet的生命周期+实现方式
    pull解析器: 反序列化与序列化
  • 原文地址:https://www.cnblogs.com/arax/p/8551911.html
Copyright © 2011-2022 走看看