@PrePersist

@PrePersist
public void prePersist() {
updatedAt = new Timestamp(System.currentTimeMillis());
createdAt = new Timestamp(System.currentTimeMillis());
}

/**
* 在持久化时,数据有变化,此方法会执行
*/
@PreUpdate
public void preUpdate() {
updatedAt = new Timestamp(System.currentTimeMillis());
}
原文地址:https://www.cnblogs.com/xingzc/p/7154574.html