这个仁兄说得好……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; } }
<mvc:annotation-driven conversion-service="conversionService" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。