1.pom.xml的文件

  <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.2.7.RELEASE</version></parent>
<dependencies><dependency><groupId>business-base</groupId><artifactId>li-common</artifactId></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.38</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency></dependencies>

2.配置代码

@Configuration
@EnableJpaAuditing
public class AuditingConfig {@Beanpublic AuditorAware<String> auditorProvider() {return new DefaultAuditorAwareImpl();}}
public class DefaultAuditorAwareImpl implements AuditorAware<String> {@Overridepublic String getCurrentAuditor() {//此处应该返回当前登录的用户的名,可以使用    private static final ThreadLocal<AuthContext> contextHolder = new InheritableThreadLocal<AuthContext>();等线程方法 将登录用户存入//return null;}}

3.抽象模型类

@MappedSuperclass
public abstract class AbstractModel extends AbstractPersistable<Long> {private static final long serialVersionUID = 7205853521241442700L;// TODO 需要实现集群化的ID生成机制
}
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class AbstractAuditModel extends AbstractModel {private static final long serialVersionUID = -8388269103763562978L;@CreatedByprivate String createdBy;@Temporal(TemporalType.TIMESTAMP)@CreatedDateprivate Date createdDate;@LastModifiedByprivate String lastModifiedBy;@Temporal(TemporalType.TIMESTAMP)@LastModifiedDateprivate Date lastModifiedDate;@Versionprivate long version;public String getCreatedBy() {return this.createdBy;}public void setCreatedBy(final String createdBy) {this.createdBy = createdBy;}public Date getCreatedDate() {return this.createdDate;}public void setCreatedDate(final Date createdDate) {this.createdDate = createdDate;}public String getLastModifiedBy() {return this.lastModifiedBy;}public void setLastModifiedBy(final String lastModifiedBy) {this.lastModifiedBy = lastModifiedBy;}public Date getLastModifiedDate() {return this.lastModifiedDate;}public void setLastModifiedDate(final Date lastModifiedDate) {this.lastModifiedDate = lastModifiedDate;}public long getVersion() {return this.version;}public void setVersion(final long version) {this.version = version;}
}

关于springdatajpa 注解@CreatedBy@LastModifiedBy@Version@LastModifiedDate的使用相关推荐

  1. @CreatedDate@CreatedBy@LastModifiedBy@LastModifiedDate

    实体类,注意需要加上@EntityListeners(AuditingEntityListener.class)这个注解才能使@CreatedDate@LastModifiedDate生效 packa ...

  2. Spring Boot中Spring data注解的使用

    文章目录 Spring Data Annotations @Transactional @NoRepositoryBean @Param @Id @Transient @CreatedBy, @Las ...

  3. jpa获取数据库当前时间_SpringDataJPA存储数据时通过注解自动设置创建时间和修改时间...

    如果我们此时是通过 Spring Data JPA进行数据库的操作,Spring Data JAP提供了Auditing特性,我们可以通过起很好的实现我们的需求. 其原因基本时通过插入监听器,当我们对 ...

  4. 近100个Spring/SpringBoot常用注解汇总!

    作者 | Guide 来源 | JavaGuide(微信公众号) 毫不夸张地说,这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景.对于每一个注解我 ...

  5. 不一样的SpringBoot注解

    目录 1. @SpringBootApplication 2. Spring Bean相关 2.1. @Autowired.@Resource 2.2. @Component,@Repository, ...

  6. 接近8000字的Spring/Spring常用注解总结|安排|

    0.前言 可以毫不夸张地说,这篇文章介绍的 Spring/SpringBoot 常用注解基本已经涵盖你工作中遇到的大部分常用的场景.对于每一个注解我都说了具体用法,掌握搞懂,使用 SpringBoot ...

  7. SpringDataJpa (二)-动态查询多表操作

    SpringDataJpa (二)-动态查询&多表操作 一.动态查询 1.Specifications动态查询 1.1 搭建测试环境 1.1.1 导入坐标 1.1.2 创建客户实体类 1.1. ...

  8. 事务配置_SSH(五)- 使用注解方式配置事务管理

    步骤1:修改applicationContext.xml步骤2:为ProductServiceImpl 添加注解步骤3:测试步骤4:MYSQL 表的类型必须是INNODB才支持事务 步骤 1 : 修改 ...

  9. Spring注解开发-Bean注册

    1.使用注解开发我们需要在applicationContext.xml文件中添加context标签. 在配置文件中开启注解扫描. <?xml version="1.0" en ...

最新文章

  1. UI培训分享:如何提升自己的UI设计能力
  2. 一个页面区分管理者和普通用户如何设计_如何从「百度知道」中删除 bai du zhi dao?...
  3. asp.net 2.0 TreeView 数据绑定(原创)
  4. Matlab 画图字体,字号的设定,图片大小和比例
  5. Linux线程池的设计
  6. 如何获取一张表的字段名
  7. linux基础-第十六单元 yum管理RPM包
  8. ls -l的功能是什么linux,Ls - Linux Wiki
  9. mysql result mysqli_MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT
  10. NASM汇编语言与计算机系统01-环境搭建
  11. 从留言簿开始,学习MonoRail MVC(三)
  12. Bp神经网络+C++实现
  13. Hello China操作系统STM32移植指南(三)
  14. 【ENVI解决经验】一处理图像就报错
  15. Hyperion神器之SmartView产品(上篇)
  16. c语言中x%y什么意思,c语言里%是什么意思?
  17. Delphi XE E2251 Ambiguous overloaded call to ‘StrPas‘错误处理
  18. ubuntu基础命令总结
  19. 数据分析需要学习哪些课程?
  20. 推荐几部好看的漫画,漫迷们不容错过的动漫新番哦

热门文章

  1. 深度学习入门笔记(二):神经网络基础
  2. B站高性能微服务架构
  3. 显示行数 设置ssh终端_mac下终端iTerm2配置
  4. p4est 2.3.2 安装
  5. 盲盒商城源码系统附源码
  6. android 手机型号占有量,2021年安卓手机性能排行及手机品牌占有率
  7. 笔记:Spring基础
  8. SEO优化之og:标签
  9. DASH推流及播放流程
  10. 微软Win10这些黑科技小功能你都用过吗