您的位置:首页 > 编程语言 > Java开发

springmvc配置全局日期转换器

2017-09-21 07:27 399 查看
package com.lai.boss.common.utils;

public class CustomDateEdtor implements WebBindingInitializer{
public void initBinder(WebDataBinder binder, WebRequest request) {
DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat dateFormat =  new SimpleDateFormat("yyyy-MM-dd");
try{
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateTimeFormat, true));
}catch (Exception e){
try {
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
} catch (Exception e2) {
reuturn null;
}
}

}
}

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="com.lai.boss.common.utils.CustomDateEdtor"/>
</property>
</bean>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: