Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-02-06'; nested exception is java.lang.IllegalArgumentException]解决
今天做springbook项目前端输入日期传到数据库保存报了一下错误
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
<form th:action="@{/toAdd}">
<h2>添加图书信息</h2>
书名:<input type="text" name="bookName"/><br/>
简介:<input type="text" name="bookNote"/><br/>
作者:<input type="text" name="bookAuthor"/><br/>
价格:<input type="text" name="bookMoney"/><br/>
出版日期:<input type="date" name="bookDate"/><br/>
<input type="submit" value="添加"/>
</form>
数据库:

@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
我试了一下果然可以!
代码如下:
@RequestMapping("/toAdd")
public String toAdd(Book book,Model model) {
bookService.addBook(book);
return "redirect:/toQueryAll";
}
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
注意这里的
Date.class是
import java.util.Date;包下的
Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-02-06'; nested exception is java.lang.IllegalArgumentException]解决的更多相关文章
- 【spring boot】spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]
spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [jav ...
- 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
异常信息如下: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value ...
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, org.springframework.boot.logging.LogLevel>]
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- 异常:Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.che ckState(ZLjava/lang/String;I)V
Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: com.google.common.bas ...
- Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.codec.digest.DigestUtils.sha1Hex(Ljava/lang/String;)Ljava/lang/String;
异常:Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.co ...
- Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type
问题描述 将项目挂载到 Myeclipse 的 tomcat 上,启动 tomcat ,报错“Initialization of bean failed; nested exception is ja ...
- nested exception is java.lang.IllegalArgumentException: warning no match for this type name: res [Xlint:invalidAbsoluteTypeName]
注:内有单词(sping)写错,请忽略,不影响程序运行 运行时报错: Exception in thread "main" org.springframework.beans.fa ...
- Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config解决
出现这个问题往往伴随 HTTP-500错误 报错信息: HTTP Status - Handler processing failed; nested exception is java.lang. ...
随机推荐
- wdos centos64位通过yum来升级PHP
通过yum list installed | grep php可以查看所有已安装的php软件 使用yum remove php -- 将所有的包删除 通过yum list php*查看是否有自己需要安 ...
- HttpServletRequest 类
目录 HttpServletRequest类有什么作用 HttpServletRequest 类的常用方法 如何获取请求参数 doGet 请求的中文乱码解决: POST 请求的中文乱码解决 请求的转发 ...
- [原创] RestartPC64-中文版v1.0.0.9
原来发布的RestartPC-中文版和英文版v1.0.0.5,在PE64下无效.所以重新编译了64位版的RestartPC64-中文版v1.0.0.9,可以在PE64下面.正常Win64系统下面重启关 ...
- CF580D Kefa and Dishes (状压DP)
枚举最后食物 #include <iostream> #include <cstdio> #include <cstring> #include <algor ...
- Unity获取脚本的CustomEditor(自定义编辑)数据
在此之前,粗略的介绍下 CustomEditor(自定义编辑). Unity对于我们创建的Mono脚本提供了属性面板的展示和修改.默认情况下,Inspector面板中会显示当前脚本类的公开字段(pub ...
- HCIA-Datacom 2.1 实验一:IPv4编址及IPv4路由基础实验
实验目的 掌握接口IPv4地址的配置方法 理解LoopBack接口的作用与含义 理解直连路由的产生原则 掌握静态路由的配置方法并理解其生效的条件 掌握通过PING工具测试网络层联通性 掌握 ...
- which 和 that 在定语从句中作介词宾语的用法
关系代词在定语从句中作介词的宾语,且介词在关系代词之前时,关系代词应该用 which:介词在定语从句句末,关系代词可以用 that 或 which. (一)He teaches in a school ...
- 在 C# 中使用 Span<T> 和 Memory<T> 编写高性能代码
目录 在 C# 中使用 Span 和 Memory 编写高性能代码 .NET 中支持的内存类型 .NET Core 2.1 中新增的类型 访问连续内存: Span 和 Memory Span 介绍 C ...
- JavaScript基础回顾知识点记录3
js 中 垃圾回收 //将不在使用的对象设置为null , js就会自动进行垃圾回收机制 var obj = {}; obj = null; js 中 数组基本介绍 数组也是一个对象 与普通对象功能类 ...
- 《吐血整理》进阶系列教程-拿捏Fiddler抓包教程(15)-Fiddler弱网测试,知否知否,应是必知必会
1.简介 现在这个时代已经属于流量时代,用户对于App或者小程序之类的操作界面的数据和交互的要求也越来越高.对于测试人员弱网测试也是需要考验自己专业技术能力的一种技能.一个合格的测试人员,需要额外关注 ...