【发布时间】:2021-05-05 04:07:07
【问题描述】:
我正在使用 springboot 和 spring-data 创建一个 crud,用户将它保存在一个变量“条目”中,我希望它只有小时:分钟:秒,我尝试使用 @JsonFormat (pattern = "HH: mm: ss" ) 但报错
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String "19:47:11": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '19:47:11' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 19:47:11 of type java.time.format.Parsed; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String "19:47:11": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '19:47:11' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 19:47:11 of type java.time.format.Parsedat [Source: (PushbackInputStream); line: 10, column: 20] (through reference chain: br.com.lucas.entity.Acao["entrada"])]
我怎样才能只节省一小时?
【问题讨论】:
-
尝试使用
LocalTime而不是LocalDateTime -
如果你想在 MySQL 中从
DATETIME中提取“小时”,有几种方法(MID(),DATE_FORMAT(),...)。如果你不想在那里做,请删除标签`'[mysql]'。 -
当我使用本地时间这个错误:“状态”:500,“错误”:“内部服务器错误”,“跟踪”:“org.springframework.dao.DataIntegrityViolationException:无法执行语句;SQL [n/a];嵌套异常是 ...
标签: java mysql spring spring-boot spring-data