加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 02:08:33 所属栏目:百科 来源:网络整理
导读:这个仁兄说得好…… 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.te

这个仁兄说得好……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" /> 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读