JPA#Interfaces总结
_开局一张图,内容全靠编
震惊:某小白熟练使用了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总结的更多相关文章
- 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 ...
- 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- ...
- 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 ...
- Spring Data JPA教程, 第六部分: Sorting(未翻译)
The fifth part of my Spring Data JPA tutorialdescribed how you can create advanced queries with Spri ...
- 持久化API(JPA)系列(三)实体Bean的开发技术-建立与数据库的连接
在EJB 2.x中.EJB有3种类型的Bean.各自是会话Bean(Session Bean).消息驱动Bean(Message-Driven Bean)和实体Bean(Entity Bean). 随 ...
- JAVA PERSISTENCE API (JPA)
13.2.1. About JPA The Java Persistence API (JPA) is the standard for using persistence in Java proje ...
- 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 ...
- Spring Data JPA Batch Insertion
转自:https://www.jeejava.com/spring-data-jpa-batch-insertion/ Spring Data JPA Batch Insertion will sho ...
- Java JPA小记
什么是JPA JPA之于ORM(持久层框架,如MyBatis.Hibernate等)正如JDBC之于数据库驱动. JDBC是Java语言定义的一套标准,规范了客户端程序访问关系数据库(如MySQL.O ...
随机推荐
- 单元测试报错:unable to find a @SpringBootConfiguration
完整异常: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBoo ...
- 设计模式课程 设计模式精讲 18-2 迭代器模式coding
1 代码演练 1.1 代码演练1(迭代器模式演练) 1.2 代码使用场景 1 代码演练 1.1 代码演练1(迭代器模式演练) 需求: 课程管理:需要实现课程可进行增添,删除,并能够打印出课程列表. u ...
- 对Python中列表和数组的赋值,浅拷贝和深拷贝的实例讲解
引用:https://www.jb51.net/article/142775.htm 列表赋值: 1 2 3 4 5 6 7 >>> a = [1, 2, 3] >>&g ...
- mysql 通过localhost可以连接IP连接不上
因为MySQL默认没开 所以需要手动设置 开MySQL启远程连接的功能,在MySQL服务器控制台上执行以下命令: 设置权限: grant all privileges on *.* to 用户名@&q ...
- dir815_FW_102.bin路由器固件解压碰到的坑
在跟随大神kczwa1进行路由器漏洞分析时,对dir815_FW_102.bin 固件文件用binwalk -e dir815_FW_102.bin命令进行解压时,在根目录squashfs-root下 ...
- 新闻网大数据实时分析可视化系统项目——3、Hadoop2.X分布式集群部署
(一)hadoop2.x版本下载及安装 Hadoop 版本选择目前主要基于三个厂商(国外)如下所示: 1.基于Apache厂商的最原始的hadoop版本, 所有发行版均基于这个版本进行改进. 2.基于 ...
- 扩展中国剩余定理 (ExCRT)
扩展中国剩余定理 (ExCRT) 学习笔记 预姿势: 扩展中国剩余定理和中国剩余定理半毛钱关系都没有 问题: 求解线性同余方程组: \[ f(n)=\begin{cases} x\equiv a_1\ ...
- require - 引入文件
导入 /** * Creates the node for the load command. Only used in browser envs. */ req.createNode = funct ...
- php+ajax实现无刷新动态加载数据技术
我们浏览有些网页的时候,当拉动浏览器的滚动条时到页底时,页面会继续自动加载更多内容供用户浏览.这种技术我暂且称它为滚屏加载技术.我们发现很多网站用到这种技术,必应图片搜索.新浪微博.QQ空间等将该技术 ...
- JavaScript之this的用法
本文我们介绍下js中this的用法. 由上图可得,默认this指向window,而在node.js中this默认指向global. 由上图可得: 1.原型链为o->MyClass.prototy ...