Cannot deserialize value of type `java.util.Date` from String "2021-12-01"
这种错误往往是前后端都会一起报的错,因为咱们的实体层也就是entity的事件类型是Date,但前端传的是个string类型,传过来的参数转换不到date类型所以接收参数时就会报这个错了
最方便的方法就是在实体层entity的时间字段加注解 @DateTimeFormat @JsonForma
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
例子:
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date startDate;