300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Cannot deserialize value of type `java.util.Date` from String expected format “yyyy-MM-dd HH:mm:ss“

Cannot deserialize value of type `java.util.Date` from String expected format “yyyy-MM-dd HH:mm:ss“

时间:2019-12-31 15:30:02

相关推荐

Cannot deserialize value of type `java.util.Date` from String expected format “yyyy-MM-dd HH:mm:ss“

在使用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="请选择开始时间"/>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。