我是靠谱客的博主 乐观期待,这篇文章主要介绍WebBindingInitializer注册全局自定义编辑器转换数据,现在分享给大家,希望可以做个参考。

实现WebBindingInitializer接口 这时Controller类中不需要@InitBinder注解注释的方法

多种转换器的优先顺序:1.@InitBinder 装配的自定义编辑器 2.ConversionService装配的自定义转换器 3.WebBindingInitializer接口装配的全局自定义编辑器

1.WebInit类 在此类中注册自定义编辑器

package com.convert;

import java.util.Date;

import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

public class WebInit implements WebBindingInitializer {

 @Override
 public void initBinder(WebDataBinder arg0, WebRequest arg1) {
  // TODO Auto-generated method stub
  arg0.registerCustomEditor(Date.class, new StringToDateConverter());
 }

}

2.springmvc.xml(配置文件)

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  <property name="webBindingInitializer">
   <bean class="com.convert.WebInit"></bean>
  </property>
 </bean>

最后

以上就是乐观期待最近收集整理的关于WebBindingInitializer注册全局自定义编辑器转换数据的全部内容,更多相关WebBindingInitializer注册全局自定义编辑器转换数据内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部