解决Failed to convert value of type java.lang.String to required type java.util.Date问题

问题描述:

spring boot在接收时间类型的时候,报Failed to convert value of type ‘java.lang.String’ to required type 'java.util.Date’的错误,如下图
在这里插入图片描述

翻译:

前端传递 string类型的数据,后端使用Date类型去接收,但是报错了。

解决方法:

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

@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") //接收时间类型

在这里插入图片描述

注解:

@DateTimeFormat 该注解自动会解析处理,会把字符串类型 按照格式yyyy-MM-dd HH:mm:ss 转换成时间类型

猜你喜欢

转载自blog.csdn.net/weixin_44161444/article/details/129282147