_开局一张图,内容全靠编

震惊:某小白熟练使用了JpaRepository和JpaSpecificationExecutor,就在简历上写下了,精通SpringData Jpa。

震惊,如果想熟练的使用SpringData JPA 对数据库进行操作,只需要重点关注上图中框住的5个接口,和其他的一些相关接口。


接口名称 要点
 Repository  1.方法命名查询。2.Query注解查询的支持。
 CrudRepository  1.继承Repository。2.Crud操作。
 PagingAndSortingRepository  1.继承了CrudRepository。2.能够分页和排序。3.无法进行复杂的查询。
 JpaRepository  1.继承了PagingAndSortingRepository。2.对返回值的类型进行了统一。3.通常与JpaSpecificationExecutor配合使用。
 JpaSpecificationExecutor  1.复杂查询的支持。2.分页排序的支持。3.通常与JpaRepository配合使用。

---


--

其他但是同样重要的。

JpaSpecificationExecutor提供的方法如下:

涉及到了两个重要的接口,分别表示查询的where已经查询的分页信息。其中分页信息中又包含了排序信息。

org.springframework.data.domain.Pageable接口用于表示分页信息,通常用其实现类org.springframework.data.domain.PageRequest

//code--begin

// PageRequest的构造又会涉及到Sort及其内部类Direction和Order
// org.springframework.data.domain.Sort
// org.springframework.data.domain.Sort.Direction
// org.springframework.data.domain.Sort.Order //---------------------------------------------
//排序的构造方法及其使用示列
//---------------------------------------------
/**
* Creates a new Sort instance using the given Orders.
*
* @param orders must not be null.
*/
public Sort(Order... orders);
/*使用示列*/
// new Sort(new Order(Direction.DESC, "id")); /**
* Creates a new Sort instance.
*
* @param orders must not be null or contain null.
*/
public Sort(List<Order> orders);
/*使用示列*/
// new Sort(Arrays.asList(new Order(Direction.DESC,"name"),new Order(Direction.ASC,"age"))); /**
* Creates a new Sort instance. Order defaults to Direction#ASC.
*
* @param properties must not be null or contain null or empty strings
*/
public Sort(String... properties);
/*使用示列*/
// new Sort("name","age"); /**
* Creates a new Sort instance.
*
* @param direction defaults to Sort#DEFAULT_DIRECTION (for null cases, too)
* @param properties must not be null, empty or contain null or empty strings.
*/
public Sort(Direction direction, String... properties);
/*使用示列*/
// new Sort(Direction.DESC,"name","age"); /**
* Creates a new Sort} instance.
*
* @param direction defaults to Sort#DEFAULT_DIRECTION (for null cases, too)
* @param properties must not be null or contain null or empty strings.
*/
public Sort(Direction direction, List<String> properties);
/*使用示列*/
// new Sort(Direction.DESC, Arrays.asList("name","age")); //---------------------------------------------
// PageRequest的构造方法
//---------------------------------------------
/**
* Creates a new PageRequest. Pages are zero indexed, thus providing 0 for page will return the first
* page.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
*/
public PageRequest(int page, int size) {
this(page, size, null);
} /**
* Creates a new PageRequest with sort parameters applied.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @param direction the direction of the Sort to be specified, can be null.
* @param properties the properties to sort by, must not be null or empty.
*/
public PageRequest(int page, int size, Direction direction, String... properties) {
this(page, size, new Sort(direction, properties));
} /**
* Creates a new PageRequest with sort parameters applied.
*
* @param page zero-based page index.
* @param size the size of the page to be returned.
* @param sort can be null.
*/
public PageRequest(int page, int size, Sort sort) {
super(page, size);
this.sort = sort;
}

//code--end

_

_

最新文章

  1. SQL2008中的Sequence
  2. jQuery3的新特性
  3. 【PCB】【项目记录】AWG任意波形产生器
  4. python---dnspython
  5. iOS tableviewcell 分割线 偏移和颜色
  6. CETV面试总结
  7. 每日学习心得:SharePoint 为列表中的文件夹添加子项(文件夹)、新增指定内容类型的子项、查询列表中指定的文件夹下的内容
  8. Oracle 11g 中恢复管理器RMAN介绍
  9. HDU 2767:Proving Equivalences(强连通)
  10. javaSE第四天
  11. HTTP常见返回代码(HTTP Status codes)的分类和含义
  12. shareplex的安装&amp;&amp;起停服务(添加新用户)
  13. vi/vim正则表达式
  14. 【性能优化】优化笔记之一:图像RGB与YUV转换优化
  15. HttpWebResponse请求状态代码
  16. 有一种设计风格叫RESTful
  17. aix Mysql安装 Oracle官方教程
  18. URAL 1180. Stone Game (博弈 + 规律)
  19. 严格模式 (JavaScript)
  20. [算法] avl树实现

热门文章

  1. spark aggregateByKey 时 java.lang.OutOfMemoryError: GC overhead limit exceeded
  2. CentOS6.9安装redis
  3. Zabbix在Docker中的应用和监控
  4. three.js的一些介绍
  5. zookeeper logs is missing zookeeper 日志丢失
  6. 尝试使用 Visual Studio Online (Cloud IDE)
  7. css常用设置
  8. NOI2019 选做
  9. AngularJs 禁止模板缓存
  10. 十四 数据库连接池&amp;DBUtils