springmvc配置全局日期转换器

来源:互联网 发布:淘宝客微信群被限制 编辑:程序博客网 时间:2024/05/17 08:23
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>

原创粉丝点击