我是靠谱客的博主 顺心身影,这篇文章主要介绍webBindingInitializer 在XML中无效,spring mvc 3.2以版本,现在分享给大家,希望可以做个参考。

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






最后

以上就是顺心身影最近收集整理的关于webBindingInitializer 在XML中无效,spring mvc 3.2以版本的全部内容,更多相关webBindingInitializer内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(104)

评论列表共有 0 条评论

立即
投稿
返回
顶部