Spring Data JPA - ZonedDateTime 格式,用于 json 序列化
2022-09-02 02:51:17
						我对的 json 序列化有问题。当转换为json时,它会生成一个巨大的对象,我不希望每次都传输所有这些数据。所以我试图将其格式化为ISO,但它不起作用。如何使其格式化?ZonedDateTime
这是我的实体类:
@MappedSuperclass
public abstract class AuditBase {
    @Id
    @GeneratedValue
    private Long id;
    @CreatedDate
    private ZonedDateTime createdDate;
    @LastModifiedDate
    private ZonedDateTime lastModifiedDate;
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    public ZonedDateTime getLastModifiedDate() {
        return lastModifiedDate;
    }
    public void setLastModifiedDate(ZonedDateTime lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
    public ZonedDateTime getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(ZonedDateTime createdDate) {
        this.createdDate = createdDate;
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @PrePersist
    public void prePersist() {
        this.createdDate = ZonedDateTime.now();
        this.lastModifiedDate = ZonedDateTime.now();
    }
    @PreUpdate
    public void preUpdate() {
        this.lastModifiedDate = ZonedDateTime.now();
    }
}
 
					 
				 
				    		 
				    		 
				    		 
				    		