zbb20181226 springboot yml 配置時間格式
阿新 • • 發佈:2018-12-26
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)