前端:
<FormItem label="发现时间" prop="mobile">
<DatePicker type="datetime"
placeholder="发现时间"
v-model="form.findTime"
@on-change="form.findTime=$event"
format="yyyy-MM-dd HH:mm:ss"
style="width: 320px">
</DatePicker>
</FormItem>
后端:
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date findTime;
因为我也是前端小白,具体原理现在还不是很懂,仅仅停留在应用层面。
真正管用的就是圈中的那一行。
不加那一行格式化完是这样的:
报错信息
"findTime-Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'findTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat @org.springframework.format.annotation.DateTimeFormat @io.swagger.annotations.ApiModelProperty java.util.Date] for value 'Wed Jun 08 2022 00:00:00 GMT+0800 (GMT+08:00)'; nested exception is java.lang.IllegalArgumentException: Invalid format: \"Wed Jun 08 2022 00:00:00 GMT+080...\""
带过去的参数是这样的:
加了那一行格式化后才是yyyy-MM-dd HH:mm:ss这样子的
完美解决日期格式问题。