数据的默认创建日期与更新日期createDate , lastUpdate(No2)
项目中每条数据的插入或更新需要记录人员,或时间
@CreatedDate:创建时间
@CreatedBy:创建人
@LastModifiedDate:最后一次修改时间
@LastModifiedBy:最后一次修改人
以上配置正确生效需要增加注解
基类
@EntityListeners(AuditingEntityListener.class)
启动类
@EnableJpaAuditing
基类配置讲解
package com.lc.data.domain;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* 抽象实体类
*/
@MappedSuperclass
@Data
@EntityListeners(AuditingEntityListener.class)
@Setter
@Getter
public abstract class BaseEntity implements Serializable {
//https://www.jianshu.com/p/3b384e873232
@Id
// @GenericGenerator(name = "uuid-key", strategy = "uuid2")
//自定义主键没搞通常
// @GenericGenerator(name = "uuidKey" ,strategy = "com.lc.data.utils.MyUuidKeyGenerator") //自定UUid
@GenericGenerator(name = "uuidKey" ,strategy = "org.hibernate.id.UUIDGenerator") // 框子已实现的主键策略
@GeneratedValue(generator = "uuidKey")
@Column(length = 36)
private String id;
@CreatedDate
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@LastModifiedDate
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}