webBindingInitializer 在XML中无效,spring mvc 3.2以版本

来源:互联网 发布:c语言函数库下载 编辑:程序博客网 时间:2024/05/11 17:06

    这个仁兄说得好……https://www.oschina.net/question/140550_20454

    default message [Failed to convert property value of type 'Java.lang.String' to required type 'java.util.Date' for property 'sdate';

package com.lanyuan.util;import java.text.SimpleDateFormat;   import java.util.Date;   import org.springframework.core.convert.converter.Converter;  /**  * spring4 mvc 的日期传递[前台-后台]bug:   * 的解决方式.包括xml的配置   *  new SimpleDateFormat("yyyy-MM-dd"); 或 new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") *    这里的日期格式必须与提交的日期格式一致  * @author lanyuan  * Email:mmm333zzz520@163.com  * date:2017-2-20  */  public class SpringMVCDateConverter implements Converter<String, Date> {  @Override  public Date convert(String source) {      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");      dateFormat.setLenient(false);      try {          return dateFormat.parse(source);      } catch (Exception e) {      dateFormat = new SimpleDateFormat("yyyy-MM-dd");      dateFormat.setLenient(false);      try {          return dateFormat.parse(source);      } catch (Exception e1) {      e1.printStackTrace();    }    }             return null;  }}


在spring mvc 的配置文件 spring-mvc.xml 添加或修改如下
<mvc:annotation-driven conversion-service="conversionService" /> 






0 0
原创粉丝点击