com.itcoon.common.jpa.base.TrackableIdPO Maven / Gradle / Ivy
package com.itcoon.common.jpa.base;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.time.LocalDateTime;
/**
* @author Miaoxia Yu
* @date 2020-11-19
*/
@MappedSuperclass
public abstract class TrackableIdPO extends IdPO {
private static final long serialVersionUID = -6593518472904845690L;
@CreationTimestamp
@Column(columnDefinition = "datetime comment '创建时间'")
private LocalDateTime creationTime;
@UpdateTimestamp
@Column(columnDefinition = "datetime comment '更新时间'")
private LocalDateTime updateTime;
public LocalDateTime getCreationTime() {
return creationTime;
}
public void setCreationTime(LocalDateTime creationTime) {
this.creationTime = creationTime;
}
public LocalDateTime getUpdateTime() {
return updateTime;
}
public void setUpdateTime(LocalDateTime updateTime) {
this.updateTime = updateTime;
}
@PrePersist
public void prePersists(){
LocalDateTime now = LocalDateTime.now();
this.creationTime = this.creationTime == null ? now : this.creationTime;
this.updateTime = this.updateTime == null ? now : this.updateTime;
}
@PreUpdate
public void preUpdate(){
LocalDateTime now = LocalDateTime.now();
this.updateTime = now;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy