1:一定要加入依赖,否则不生效:
<!--日期格式化依赖-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
2:在实体类get方法上加入注解: private Date createTime;
@JsonFormat(pattern = "yyyy年MM月dd日 HH:mm:ss", timezone = "GMT+8")
public Date getCreateTime() {
return createTime;
} public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
注:
pattern = "yyyy年MM月dd日 HH:mm:ss",还可以是其他格式