这是我的带有审计字段的实体的基类。对于字段@CreatedDate、@LastModifiedDate,默认情况下它会节省我的系统时间。我的要求是以 UTC 格式保存时间戳。
有人有解决这个问题的方法吗?
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import lombok.Data;
@MappedSuperclass
@Data
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseEntity {
@LastModifiedDate
@Column(name="last_modified_datetime")
private LocalDateTime lastModifiedDateTime;
@CreatedDate
@Column(name="created_datetime")
private LocalDateTime createdDateTime;
}
这是时区的问题。使用此代码进行 Spring Boot。
@PostConstruct
public void setTimeZone() {
TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)