Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
2015-07-03 15:52
756 查看
在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方法
@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 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方法
@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日期格式与页面日期格式要一致!
相关文章推荐
- 【Streaming】我在拓扑中使用了Ack机制,为什么在Storm UI上有大量Failed数据?
- JS 前端框架7 一个简单的require功能
- Easy Ui 加Loading
- error C2440: ’static_cast’ : cannot convert from ‘UINT (__thiscall CStaticLink::* )(CPoint)’ to ‘LRE
- Andriod UiAutomator 使用 Jenkins 实现持续集成
- NFinal学习笔记 02—NFinalBuild
- IOS自动化测试之UIAutomation Test学习——first step:Instrument
- NSOperationQueue和GCD的区别,以及在什么场合下使用
- Android酷炫实用的开源框架(UI框架)
- 主动呼叫KVO(NSKeyValueObserverNotification)
- 关于${pageContext.request.contextPath}的理解
- FlexBuilder无法连接Flashplayer调试器进行DEBUG
- ARP协议详解之Gratuitous ARP(免费ARP)
- UICollectionView基础
- web项目编译出错时,原因之一,可能是build path 中order and Export引起
- UITableViewCell自动调整高度相关资料整理
- ARP协议详解之Gratuitous ARP(免费ARP)
- Guess3
- Qt Project Build error PRJ0019: 工具从"Moc'ing xxx.h..."
- Android酷炫实用的开源框架(UI框架)