为什么80%的码农都做不了架构师?>>>   

本文主要研究一下Spring Data Auditable接口的变化

1.12.8.RELEASE版本

spring-data-commons-1.12.8.RELEASE-sources.jar!/org/springframework/data/domain/Auditable.java

import java.io.Serializable;import org.joda.time.DateTime;/*** Interface for auditable entities. Allows storing and retrieving creation and modification information. The changing* instance (typically some user) is to be defined by a generics definition.* * @param <U> the auditing type. Typically some kind of user.* @param <ID> the type of the audited type's identifier* @author Oliver Gierke*/
public interface Auditable<U, ID extends Serializable> extends Persistable<ID> {/*** Returns the user who created this entity.* * @return the createdBy*/U getCreatedBy();/*** Sets the user who created this entity.* * @param createdBy the creating entity to set*/void setCreatedBy(final U createdBy);/*** Returns the creation date of the entity.* * @return the createdDate*/DateTime getCreatedDate();/*** Sets the creation date of the entity.* * @param creationDate the creation date to set*/void setCreatedDate(final DateTime creationDate);/*** Returns the user who modified the entity lastly.* * @return the lastModifiedBy*/U getLastModifiedBy();/*** Sets the user who modified the entity lastly.* * @param lastModifiedBy the last modifying entity to set*/void setLastModifiedBy(final U lastModifiedBy);/*** Returns the date of the last modification.* * @return the lastModifiedDate*/DateTime getLastModifiedDate();/*** Sets the date of the last modification.* * @param lastModifiedDate the date of the last modification to set*/void setLastModifiedDate(final DateTime lastModifiedDate);
}

可以看到这个版本使用的joda-time的DateTime

2.0.7.RELEASE版本

spring-data-commons-2.0.7.RELEASE-sources.jar!/org/springframework/data/domain/Auditable.java

/*** Interface for auditable entities. Allows storing and retrieving creation and modification information. The changing* instance (typically some user) is to be defined by a generics definition.* * @param <U> the auditing type. Typically some kind of user.* @param <ID> the type of the audited type's identifier* @author Oliver Gierke*/
public interface Auditable<U, ID, T extends TemporalAccessor> extends Persistable<ID> {/*** Returns the user who created this entity.* * @return the createdBy*/Optional<U> getCreatedBy();/*** Sets the user who created this entity.* * @param createdBy the creating entity to set*/void setCreatedBy(U createdBy);/*** Returns the creation date of the entity.* * @return the createdDate*/Optional<T> getCreatedDate();/*** Sets the creation date of the entity.* * @param creationDate the creation date to set*/void setCreatedDate(T creationDate);/*** Returns the user who modified the entity lastly.* * @return the lastModifiedBy*/Optional<U> getLastModifiedBy();/*** Sets the user who modified the entity lastly.* * @param lastModifiedBy the last modifying entity to set*/void setLastModifiedBy(U lastModifiedBy);/*** Returns the date of the last modification.* * @return the lastModifiedDate*/Optional<T> getLastModifiedDate();/*** Sets the date of the last modification.* * @param lastModifiedDate the date of the last modification to set*/void setLastModifiedDate(T lastModifiedDate);
}

可以看到新版版本,去掉了强制依赖joda-time,改为在接口定义新增泛型来表达,该泛型要求实现TemporalAccessor接口 另外,返回值的类型都改为了Optional

小结

新版的Auditable主要有两个比较大的变动:

  • 时间类型改为泛型定义,要求具体类型实现TemporalAccessor接口
  • 返回值统一返回Optional类型

doc

  • 3.9. Auditing

转载于:https://my.oschina.net/go4it/blog/1820807

聊聊Spring Data Auditable接口的变化相关推荐

  1. 干货|一文读懂 Spring Data Jpa!

    有很多读者留言希望松哥能好好聊聊 Spring Data Jpa!其实这个话题松哥以前零零散散的介绍过,在我的书里也有介绍过,但是在公众号中还没和大伙聊过,因此本文就和大家来仔细聊聊 Spring D ...

  2. apache ignite_使用Spring Data的Apache Ignite

    apache ignite Spring Data提供了一种统一而简便的方法来访问不同类型的持久性存储,关系数据库系统和NoSQL数据存储. 它位于JPA之上,添加了另一层抽象并定义了基于标准的设计以 ...

  3. Spring Data JPA教程

    在Java类或对象与关系数据库之间管理数据是一项非常繁琐且棘手的任务. DAO层通常包含许多样板代码,应简化这些样板代码,以减少代码行数并使代码可重复使用. 在本教程中,我们将讨论Spring数据的J ...

  4. 使用Spring Data的Apache Ignite

    Spring Data提供了一种统一而简单的方法来访问不同类型的持久性存储,关系数据库系统和NoSQL数据存储. 它位于JPA之上,添加了另一层抽象并定义了基于标准的设计以在Spring上下文中支持持 ...

  5. 【SpringBoot框架篇】11.Spring Data Jpa实战

    文章目录 1.简介 1.1.JPA 1.2.Spring Data Jpa 1.3.Hibernate 1.4.Jpa.Spring Data Jpa.Hibernate三者之间的关系 2.引入依赖 ...

  6. Spring Data Elasticsearch聚合搜索实战

    准备环境 1 安装Elasticsearch 5.5.2 (略) 2 使用爬虫爬取厦门人才网相关招聘信息(略) 通过elasticsearch-head插件可以看到我们已经爬取很多数据了 3 在项目中 ...

  7. Spring Data JPA-根据Repository接口关键字生成SQL

    Spring Data JPA-根据Repository接口关键字生成SQL JPA支持根据Repository接口中的方法名生成SQL,常用的CRUD都可以实现. 支持的查询方法主题关键字(即前缀, ...

  8. Spring Data JPA 自定义Repository接口与子接口

    上篇文章介绍了 Repository接口的使用(Spring Data JPA介绍与Spring的整合),接下来重点掌握 Repository的CrudRepository子接口下的子接口. 在dao ...

  9. mongodb数据库java接口,MongoDB —— 使用Spring Data MongoDB操作数据库

    我们使用Spring Data MongoDB可以方便的在Spring boot项目中操作MongoDB 文档地址:https://docs.spring.io/spring-boot/docs/2. ...

最新文章

  1. 关于软件开发环境的思考
  2. ElasticSearch知识汇总
  3. LR与SVM的相同点和不同点
  4. 一个跨国银行的敏捷转型案例要点之全员培训
  5. python测试开发面试题_python测试开发面试之深浅拷贝
  6. SAP License:如何做好ERP系统验收测试
  7. php与mysqli,如何通过PHP与MySQLi保持联系
  8. 把握初期企业的发展战略规划
  9. “第八期央企CIO论坛”成功举办
  10. Redhat Linux安装JDK 1.7
  11. BMFont工具生成自定义字体
  12. NX的尺寸控制与半径补偿(重要)
  13. 渐变按钮 css,CSS3 Gradient Buttons
  14. HHKB静电容键盘真是程序员键盘吗?
  15. [SHOI2017]期末考试
  16. LNMP部署应用——架设Discuz论坛——实验过程超详细!快来跟做!
  17. JavaScript中的scrollTop(js中的scrollTop,滚动到顶部,javascript滚动到顶部)
  18. android文件下载功能实现,Android中DownloadManager实现文件下载实例详解
  19. 面积与弦长_Simplelife_新浪博客
  20. 黑白翻转棋算法java实现

热门文章

  1. 正向有功正向无功_电表_正向有功、反向无功
  2. xp和linux的引导文件,Linux与XP双系统中grub引导配置笔记
  3. Android Studio出现cannot resolve symbol httpclient解决方法
  4. vscode禁用 json 添加注释时的报错
  5. java调用数据库存储过程_Java调用SQL Server的存储过程详解
  6. js遍历list数据显示到h5页面_大数据应用 | 带你找个地方去避暑
  7. 亚信安全认证acse_重装出发 | 2019亚信安全合作伙伴大会珠海站召开
  8. rk3288 android5.1 java 层使用 su 获取 root 权限
  9. 初恋为何成为最美的爱情(下)
  10. 无人车致命车祸视频曝光:Uber技术失败的实锤,一场本可避免的灾难