方法一:
可以在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;
引入依賴:
復制代碼
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.0</version>
</dependency>
<!--使用DataFormat注解-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.5.RELEASE</version>
<scope>compile</scope>
</dependency>
復制代碼
方法三:
可以在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)