您的位置:首页 > 其它

WebBindingInitializer学习

2016-03-22 14:26 357 查看
今天在看开源代码的时候遇到了这个接口,于是查阅了下相关的资料

Spring web mvc学习笔记

/article/5794271.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 了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: