使用elementui的 DatePicker 日期选择器,保存到后台时报错400,报错如下:
message: "JSON parse error: Cannot deserialize value of type `java.util.Date` from String \"2022-07-13T16:00:00.000Z\": not a valid representation (error: Failed to parse Date value '2022-07-13T16:00:00.000Z': Unparseable date: \"2022-07-13T16:00:00.000Z\"); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String \"2022-07-13T16:00:00.000Z\": not a valid representation (error: Failed to parse Date value '2022-07-13T16:00:00.000Z': Unparseable date: \"2022-07-13T16:00:00.000Z\")\n at [Source: (PushbackInputStream); line: 1, column: 255] (through reference chain: com.lanren312.ClassReq[\"startTime\"])"
解决办法:
保存时用这个 *** 重点
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd") private Date startTime;
查询用@DateTimeFormat
@DateTimeFormat(pattern = "yyyy-MM-dd") private Date crdtStart;