问题描述:
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 转换成时间类型