Links

在模型类上添加注解

  1. import javax.persistence.EntityListeners;
  2. import org.springframework.data.jpa.domain.support.AuditingEntityListener;
  3. @EntityListeners(AuditingEntityListener.class)

在字段上添加注解

  1. import org.springframework.data.annotation.CreatedDate;
  2. import org.springframework.data.annotation.LastModifiedDate;
  3. @CreatedDate
  4. @Column(nullable = false, updatable = false)
  5. private Date createdAt;
  6. @LastModifiedDate
  7. @Column(nullable = false)
  8. private Date updatedAt;

在启动类上添加注解

  1. import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
  2. @EnableJpaAuditing