开启
@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<String> {
@Override
public String getCurrentAuditor() {
return "xixicat";
}
}
参考
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。