Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
2014-04-26 12:28
621 查看
在springmvc中如果表单属性的类型是日期型时,从页面绑定字符串数据会出错
Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'expert.birthdate'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [java.util.Date]
for property 'birthdate': no matching editors or conversion strategy found
解决方法
1.控制器继承 extends SimpleFormController
2.重写initBinder方法
Java代码
注意SimpleDateFormat日期格式与页面日期格式要一致!
Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property 'expert.birthdate'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [java.util.Date]
for property 'birthdate': no matching editors or conversion strategy found
解决方法
1.控制器继承 extends SimpleFormController
2.重写initBinder方法
Java代码
@InitBinder protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); CustomDateEditor dateEditor = new CustomDateEditor(fmt, true); binder.registerCustomEditor(Date.class, dateEditor); super.initBinder(request, binder); }
注意SimpleDateFormat日期格式与页面日期格式要一致!
相关文章推荐
- Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
- Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for pr
- 关于springMVC中:Failed to convert property value of type 'java.lang.String' to required type 'java.util
- [置顶] 解决:Failed to convert value of type 'java.lang.String' to required type 'java.util.Date';
- 解决:Failed to convert value of type 'java.lang.String' to required type 'java.util.Date';
- Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill
- spring Failed to convert property value of type 'java.lang.String' to required type 'int' for proper
- spring Failed to convert property value of type 'java.lang.String' to required type 'int' for proper
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx'
- Failed to convert property value of type [java.lang.String] to required type [int]
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx'
- spring mvc 数据绑定报错 Failed to convert property value of type 'java.lang.String' to required type 'int'
- Failed to convert property value of type [java.lang.String] to required type [boolean] for property
- springmvc-- Failed to convert property value of type 'java.lang.String' to required type
- 表单提交时候"Failed to convert property value of type [java.lang.String] to
- Failed to convert from type java.lang.String to type java.util.Date for value………解决办法
- Failed to convert from type java.lang.String to type java.util.Date for value………解决办法
- Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipa
- Failed to convert property value of type 'java.util.LinkedHashMap' to required