Spring JPA Data Auditing

阐述如何使用Spring的JpaAuditing来方便的给auditing相关的字段赋值
官方文档
baeldung 示例

注意:
来自官方文档:

If you have multiple implementations registered in the ApplicationContext, you can select the one to be used by explicitly setting the auditorAwareRef attribute of @EnableJpaAuditing.

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
@EnableJpaAuditing(auditorAwareRef="auditorProvider")
public class PersistenceConfig {

...

@Bean
AuditorAware<String> auditorProvider() {
return new AuditorAwareImpl();
}

...

}