您好,欢迎来到五一七教育网。
搜索
您的当前位置:首页完美解决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 报错

来源:五一七教育网

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格式类型,前提取出进行展示.

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 517ttc.cn 版权所有 赣ICP备2024042791号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务