1

开启

@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";
    }
}

参考


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...