SpringDataJpa的auditing功能
开启
@SpringCloudApplication
@EnableJpaAuditing
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
标记
@Entity
@Table(name = "sample")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
public class Sample {
@Tolerate
public Sample(){
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ApiModelProperty("创建日期")
@CreatedDate
private Date createdAt;
@ApiModelProperty("创建者")
@CreatedBy
private String createdBy;
@ApiModelProperty("更新日期")
@LastModifiedDate
private Date lastModifiedAt;
@ApiModelProperty("更新者")
@LastModifiedBy
private String lastModifiedBy;
@ApiModelProperty("版本号")
@Version
private Long version;
@Override
public String toString(){
return ToStringBuilder.reflectionToString(this);
}
}
提供user
@Component
public class AuditorProvider implements AuditorAware {
@Override
public String getCurrentAuditor() {
return "xixicat";
}
}
参考
-
spring-data-jpa-auditing
-
spring-data-jpa-tutorial-auditing-part-one
-
spring-data-jpa-tutorial-auditing-part-two
关键字:产品经理
版权声明
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!