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)