Chinaunix首页 | 论坛 | 博客
  • 博客访问: 127278
  • 博文数量: 40
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 236
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-04 09:56
个人简介

小小博客,不足为外人道

文章分类

全部博文(40)

分类: Java

2018-06-20 16:32:47

今天在一个springMVC项目里出现以下报错

Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found

报错内容大概理解,就是前端输入给后台的是一个字符串,后台需要Date类型嘛,这之间的转换出错,解决办法是:

在对应的controller中增加属性编辑器:


点击(此处)折叠或打开

  1. @InitBinder
  2. protected void initBinder(WebDataBinder binder) {
  3.     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  4.     binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
  5. }



参考原文:https://www.cnblogs.com/rollenholt/p/3890415.html
阅读(1890) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~