OffsetDateTime字段java8:无法从TemporalAccessor获取OffsetDateTime

时间:2018-06-04 11:30:24

标签: java datetime java-8

我将日期时间(type='datetime-local')字段从UI传递到后端。我发送的格式为yyyy-mm-ddThh:mm:ss。 在后端我使用OffsetDateTime来保存这个值

class Test {
...
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssZ")
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModelProperty(required = false, hidden = true)
OffsetDateTime expiryDate;
}

然后我试图将其存储在字段类型的' DATETIME'的mysql DB中。

Timestamp expiryDate = offsetDateTimeToTimestamp(tag.getExpiryDate());
parameterMap.addValue("expiryDate", expiryDate);
namedJdbcTemplate.update(ADD_QUERY, parameterMap, keyHolder);

执行此操作时,我收到错误消息:

Caused by: java.time.DateTimeException: Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2018-09-20T03:02:55 of type java.time.format.Parsed

Caused by: com.fasterxml.jackson.databind.JsonMappingException: Failed to deserialize java.time.OffsetDateTime: (java.time.DateTimeException) Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2018-09-20T03:02:55 of type java.time.format.Parsed

有人可以帮我完成这项任务吗?

0 个答案:

没有答案