在使用elementplus的el-date-picker 的时候后端报错:
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "-09-08T00:00:00.000Z": expected format "yyyy-MM-dd HH:mm:ss"; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "-09-08T00:00:00.000Z": expected format "yyyy-MM-dd HH:mm:ss"<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 76] (through reference chain: com.aifast.domain.Application["startTime"])]
<el-date-pickerv-model="editApplication.endTime"type="datetime"format="YYYY-MM-DD HH:mm:ss"placeholder="请选择结束时间"/>
后端加上注解也不管用
@TableField("start_time")@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss",locale="zh")private Date startTime;
打印前端往后端传的值,如下图:
发现并没有格式化。
后来再翻阅elementplusel-date-picker 的属性发现了value-format属性,官方的解释如下
后来指定了value-format就搞定了。
<el-date-pickerv-model="editApplication.startTime"type="datetime"format="YYYY-MM-DD HH:mm:ss"value-format="YYYY-MM-DD HH:mm:ss"placeholder="请选择开始时间"/>