WebBindingInitializer学习

今天在看开源代码的时候遇到了这个接口,于是查阅了下相关的资料

Spring web mvc学习笔记

http://www.cnblogs.com/crazy-fox/archive/2012/02/18/2357699.html

WebBindingInitializer 接口来实现全局注册 使用@InitBinder只能对特定的controller类生效,为注册一个全局的customer Editor,可以实现接口WebBindingInitializer 。

复制代码
public class CustomerBinding implements WebBindingInitializer {
@Override
public void initBinder(WebDataBinder binder, WebRequest request) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));

}
复制代码

并修改 servlet context xml配置文件

复制代码
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean
class="net.zhepu.web.customerBinding.CustomerBinding" />
</property>
</bean>
复制代码

但这样一来就无法使用mvc:annotation-driven  了

posted @ 2016-03-22 14:26  yuan.net  阅读(266)  评论(0编辑  收藏  举报