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?
  • 相关阅读:
    java线程池
    缓存命中
    dubbo面向服务使用
    ActiveMQ
    创建证书
    struts2的运行原理以及底层的工作机制
    jdbc,mybatis,hibernate各自优缺点及区别
    struts2与springmvc的区别
    linux vi 命令编辑操作
    Linux FTP基本操作命令 ( 序列二 ftp)
  • 原文地址:https://www.cnblogs.com/arax/p/8551911.html
Copyright © 2011-2022 走看看