簡體   English   中英

Java 8日期格式的Spring Boot

[英]Spring Boot with Java 8 Date format

我試圖在springboot中使用Java 8 LocalDate

我放

compile ("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")

整數.gradle

@JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonSerialize(using = LocalDateSerializer.class)
    private LocalDate dia;

在屬性中,我有:

spring.jackson.date-format=dd/MM/yyyy HH:mm:ss

但不起作用,當我嘗試發布時出現此錯誤:

{
  "timestamp": "02/09/2015 11:32:15",
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.http.converter.HttpMessageNotReadableException",
  "message": "Could not read document: Text '10/10/2015' could not be parsed at index 0 (through reference chain: br.com.lumera.entity.Feriado[\"dia\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Text '10/10/2015' could not be parsed at index 0 (through reference chain: br.com.lumera.entity.Feriado[\"dia\"])",
  "path": "/atos/feriado/"
}

我怎樣才能解決這個問題?

ks

默認情況下, LocalDateDeserializer類接受的格式為yyyy-mm-dd。 您必須修改前端組件,以便它相應地格式化日期。 如果要在Serializer / Deserializer中指定其他格式,則必須使用自定義java.time.format.DateTimeFormatter實例化它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM