zbb20181226 springboot yml 配置時間格式 格式化日期 格式化時間


 

spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: Asia/Shanghai 
 
 

方法一: 
可以在apllication.property加入下面配置就可以

#時間戳統一轉換
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8

方法二:

  @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
  @DateTimeFormat(pattern="yyyy-MM-dd")
  private Date createdDate;
@JsonFormat(timezone = "GMT+8", pattern = "yyyyMMddHHmmss")
private Date createTime;

方法三: 
可以在apllication.yml加入下面配置就可以

#時間戳統一轉換
spring:
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
  time-zone: GMT+8

注意: 
@JsonIgnoreProperties此注解是類注解,作用是json序列化時將java bean中的一些屬性忽略掉,序列化和反序列化都受影響。 
@JsonIgnoreProperties(value = { "word" }) 。 
@JsonIgnore此注解用於屬性或者方法上(最好是屬性上),作用和上面的@JsonIgnoreProperties一樣。 
@JsonSerialize此注解用於屬性或者getter方法上,用於在序列化時嵌入我們自定義的代碼,比如序列化一個double時在其后面限制兩位小數點。 
@JsonSerialize(using = CustomDoubleSerialize.class) 
@JsonDeserialize此注解用於屬性或者setter方法上。 
用於在反序列化時可以嵌入我們自定義的代碼,類似於上面的 
@JsonSerialize 
@JsonDeserialize(using = CustomDateDeserialize.class)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM