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

震惊:某小白熟练使用了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

_

_

JPA#Interfaces总结的更多相关文章

  1. JavaPersistenceWithHibernate第二版笔记Getting started with ORM-001用JPA和Hibernate实现HellowWorld(JTA、Bitronix)

    一.结构 二.model层 1. package org.jpwh.model.helloworld; import javax.persistence.Entity; import javax.pe ...

  2. SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则(@EnableJpaRepositories、<jpa:repositories>)

    一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF- ...

  3. Spring Data JPA Tutorial Part Nine: Conclusions(未翻译)

    This is the ninth and the last part of my Spring Data JPA tutorial. Now it is time to take a look of ...

  4. Spring Data JPA教程, 第六部分: Sorting(未翻译)

    The fifth part of my Spring Data JPA tutorialdescribed how you can create advanced queries with Spri ...

  5. 持久化API(JPA)系列(三)实体Bean的开发技术-建立与数据库的连接

    在EJB 2.x中.EJB有3种类型的Bean.各自是会话Bean(Session Bean).消息驱动Bean(Message-Driven Bean)和实体Bean(Entity Bean). 随 ...

  6. JAVA PERSISTENCE API (JPA)

    13.2.1. About JPA The Java Persistence API (JPA) is the standard for using persistence in Java proje ...

  7. Why I don't want use JPA anymore

    转自:https://dev.to/alagrede/why-i-dont-want-use-jpa-anymore-fl Great words for what is considered by ...

  8. Spring Data JPA Batch Insertion

    转自:https://www.jeejava.com/spring-data-jpa-batch-insertion/ Spring Data JPA Batch Insertion will sho ...

  9. Java JPA小记

    什么是JPA JPA之于ORM(持久层框架,如MyBatis.Hibernate等)正如JDBC之于数据库驱动. JDBC是Java语言定义的一套标准,规范了客户端程序访问关系数据库(如MySQL.O ...

随机推荐

  1. 「CH6101」最优贸易

    「CH6101」最优贸易 传送门 考虑一种贪心的思想:我们要尽量买价格小的货物,并尽量高价转卖. 我们记 : \(mn[i]\) 为从点 \(1\) 走到点 \(i\) 经过的价格最小的货物的价格. ...

  2. win7 X64 进程名称不一致,导致杀进程失效!

    win7 x86, 或 win10 x64 环境下, x86的进程名称 ”aaa.exe“ 在win7 x64下面显示为  ”aaa.exe *32“

  3. 题解 CF165D 【Beard Graph】

    思路:将黑边标记为1,白边标记为100000,树链剖分 如果查询时ans超过100000,那就有白边,输出-1,不然直接输出ans #include<bits/stdc++.h> #def ...

  4. CF 1278C Berry Jam 题解

    Forewords 说实话我是被图吸引进来的23333,图画的真的挺好看. 题意 你从一个梯子下到地下室,梯子左右两边各有 \(n\) 瓶果酱排成一排,果酱口味为草莓味或蓝莓味,你每次只能吃你左边或右 ...

  5. 一探torch.nn究竟“What is torch.nn really?”

    来自: https://pytorch.org/tutorials/beginner/nn_tutorial.html <What is torch.nn really?>这文章看起来不能 ...

  6. Day3-Q-修补木桶 HihoCoder1362

    一只木桶能盛多少水,并不取决于桶壁上最高的那块木板,而恰恰取决于桶壁上最短的那块. 已知一个木桶的桶壁由N块木板组成,第i块木板的长度为Ai. 现在小Hi有一个快捷修补工具,每次可以使用修补工具将连续 ...

  7. 「USACO5.4」奶牛的电信Telecowmunication

    传送门 Luogu 解题思路 题目要求的是最小割点集,考虑用最小割来做. 所有边容量为1,直接求最小割? 这样肯定会出错,比如这种情况: 从最左边的点到最右边的点的最小割为2,但是答案是1,只要破坏中 ...

  8. mysqlworkbench导入sql文件

    直接给上神秘地址怕自己以后忘记:https://blog.csdn.net/u010801439/article/details/78762387

  9. 计算机网络中OSI参考模型

    OSI参考模型 应用层 包括所有能产生网络流量的程序 DNS属于这一层 表示层 用来判断传输之前是否进行加密或压缩处理(二进制.ASCII) 比如出现乱码情况,可能就是表示层的问题 会话层 一个浏览器 ...

  10. PWM与时间片思想

    改编自:http://www.moz8.com/thread-79049-1-1.html 什么是PWM? PWM:脉冲宽度调制,由于在数字电路(或者单片机)输出模拟信号的成本高昂,换句话说,受制于只 ...