完美解决报错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'
首先这个错误的意思是 前台页面传递在string类型的时间数据,比如'2020-05-31 10:00:00' 后台使用Date类型去接收,但是报错了。
解决方法:
要解决这个问题其实很简单, 在接收的字段上面,添加下面的注解 就可以了
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") //返回时间类型
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") //接收时间类型
private Date startTime;
注解解释:
@DateTimeFormat
该注解自动会解析处理,会把字符串类型 按照格式yyyy-MM-dd HH:mm:ss 转换成时间类型
@JsonFormat
这个注解是spring里面controller返回到页面的的转换. 把时间类型 转换成JSON格式类型,
前提取出进行展示.
完美解决报错Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'的更多相关文章
- 解决spring mvc 上传报错,Field [] isn't an enum value,Failed to convert value of type 'java.lang.String[]' to required type '
没有选择附件,但是点击上传按钮的时候会报错. 之前不选择文件,直接上传空文件是可以的,后来不知道改了什么就不行了. 错误信息: -- :: [http--] TRACE org.springframe ...
- 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';
后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...
- Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDate';
springboot jdbc查询使用LocalDate报:Failed to convert value of type 'java.lang.String' to required type 'j ...
- SpringBoot 项目启动 Failed to convert value of type 'java.lang.String' to required type 'cn.com.goldenwater.dcproj.dao.TacPageOfficePblmListDao';
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tac ...
- spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'
在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错: Failed to convert property value of type [java.lang.String] ...
- Java 异常 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'
查询时发送给服务器的日期的字符串格式:yyyy-MM-dd HH:mm:ss 服务器接收到日期的字符串之后,向 MySQL 数据库发起查询时,因为没有指定日期时间格式,导致字符串数据不能正确地转换为日 ...
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx': no matching editors or conversion strategy found
今天在完成项目的时候遇到了下面的异常信息: 04-Aug-2014 15:49:27.894 SEVERE [http-apr-8080-exec-5] org.apache.catalina.cor ...
- Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFa ...
- Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'
我的情况是:在applicationContext.xml文件中配置 <bean id="member" class="com.entity.Member" ...
随机推荐
- 在for循环里面的++i与i++的区别
++i与i++在表面上没有什么区别 for(语句 1;语句 2;语句 3) 语句 1 在循环(代码块)开始前执行 语句 2 定义运行循环(代码块)的条件 语句 3 在循环(代码块)已被执行之后执行 ( ...
- Java——SSM整合所需的Maven配置文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- 学习Vue第四节,v-model和双向数据绑定
Vue指令之v-model和双向数据绑定 <!DOCTYPE html> <html> <head> <meta charset="utf-8&qu ...
- 播放音乐(mciSendString)
1.需要引用命名空间using System.Runtime.InteropServices; 这里只是做了个简单的播放功能,想了解更多查看它的官方文档 [DllImport("winmm. ...
- JAVA基础篇 之 finalize()方法的作用
我们知道java有垃圾回收器负责回收无用对象占据的内存资源,但也有特殊情况:假设你的对象(并非使用new)获得了一块特殊的内存区域,由于垃圾回收器只知道回收那些经由new分配的内存,所以它不知道如 ...
- RabbitMQ的轮询模式和公平分发
一.常用的消息模式 我们在工作的使用中,经常会遇到多个消费者监听同一个队列的情况,模型如下图所示: 当有多个消费者时,我们的消息会被哪个消费者消费呢,我们又该如何均衡消费者消费信息的多少呢: 主要有两 ...
- leetcode_二叉树验证(BFS、哈希集合)
题目描述: 二叉树上有 n 个节点,按从 0 到 n - 1 编号,其中节点 i 的两个子节点分别是 leftChild[i] 和 rightChild[i]. 只有 所有 节点能够形成且 只 形成 ...
- ubuntu安装java方法
详情请点链接:https://www.digitalocean.com/community/tutorials/how-to-install-java-with-apt-get-on-ubuntu-1 ...
- [hdu5411 CRB and Puzzle]DP,矩阵快速幂
题意:给一个有向图,从任意点开始,最多走m步,求形成的图案总数. 思路:令dp[i][j]表示走j步最后到达i的方法数,则dp[i][j]=∑dp[k][j-1],其中k表示可以直接到达i的点,答案= ...
- fakebook
0x01 查看robots.txt 发现user.php.bak文件 得到源码 <?php class UserInfo { public $name = ""; publi ...