When using elementplus's el-date-picker, the backend reports an error:
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2022-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 "2022-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-picker
v-model="editApplication.endTime"
type="datetime"
format="YYYY-MM-DD HH:mm:ss"
placeholder="请选择结束时间"
/>
Adding annotations to the back end doesn't work
@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;
Print the value passed from the front end to the back end, as shown in the figure below:
Found and not formatted.
Later, I looked through the attributes of elementplus el-date-picker and found the value-format attribute. The official explanation is as follows
attribute name | illustrate | type | optional value | Defaults |
---|---|---|---|---|
value-format | Optional, the format of the bound value. If not specified, the binding value is a Date object | string | View date format | —— |
Later, specify the value-format and it will be done.
<el-date-picker
v-model="editApplication.startTime"
type="datetime"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
placeholder="请选择开始时间"
/>