栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

完美解决Failed to convert value of type java.lang.String to required type java.util.Date 报错

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

完美解决Failed to convert value of type java.lang.String to required type java.util.Date 报错

springboot在接收时间类型的时候,报Failed to convert value of type ‘java.lang.String’ to required type 'java.util.Date’的错误,应该怎么解决呢

错误翻译:
首先上面的错误的意思是 前台传递 string类型的数据,后台使用Date类型去接收,但是报错了。

解决之道:
springboot要解决这个问题很简单,在接收的字段上面,添加下面的注解 就OK

@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这个注解是从数据库查询出来,返回到页面的的转换. 把时间类型 转换成JSON格式类型,前提取出进行展示.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/777207.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号