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

震惊:某小白熟练使用了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. C语言调试器GDB和LLDB的使用方法

    调试器的使用 编译输出带调试信息的程序 调试信息包含:指令地址.对应源代码及行号 指令完成后,回调 LINUX使用GDB MAX使用LLDB 使用说明 // 开始调试testlib程序 lldb te ...

  2. 洛谷 P5242 [USACO19FEB]Cow Dating P

    这道题很有意思. 不难发现,对于一个区间 \([l, r]\),恰好只有一个奶牛接受邀请的概率为 \[\prod_{i=l}^r(1-p_i) \cdot \sum_{i=l}^r \frac {p_ ...

  3. linux系统登陆过程

    一.物理直连登陆过程 初始化进程init 会根据直接连接的字符终端设备,打开getty程序,并关联在字符终端设备上tty1/2/3/4/5/6/7....上,在不同的终端设备上提示用户输入信息,等待终 ...

  4. 守神漏洞扫描器V1.2

    主界面 指纹利用 漏洞库 怎么说呢,个人感觉这个扫描器跟小哲的Test404Fuzzer差不多~ 就是功能多了旁站查询.C段查询.而且这款工具的exp比Test404Fuzzer的多了几个~ 总体来说 ...

  5. 简单讲解什么是黑帽SEO

    此文章主要讲的是黑帽SEO之搜索引擎劫持: SEO(Search Engine Optimization)搜索引擎优化,简单来说,就是让网站的排名更高,比如,搜索"博客"这个关键字 ...

  6. 【剑指Offer面试编程题】题目1510:替换空格--九度OJ

    题目描述: 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 输入: 每个 ...

  7. Restful API及接口安全

    一.简介 REST(Representational State Transfer,具体状态转移),是一种基于HTTP协议.URI(统一资源定位符).JSON和XML这些现有协议与标准的,针对网络应用 ...

  8. 神奇的URL Schemes大全

    微信: 打开微信 wechat:// 微信扫一扫 weixin://scanqrcode 支付宝: 蚂蚁庄园 alipays://platformapi/startapp?appId=66666674 ...

  9. Spring中获取web项目的根目录

    spring 在 org.springframework.web.util 包中提供了几个特殊用途的 Servlet 监听器,正确地使用它们可以完成一些特定需求的功能; WebAppRootListe ...

  10. 在html中创建自定义标签

    创建并使用自定义标签 Web Components 标准非常重要的一个特性是,它使开发者能够将HTML页面的功能封装为 custom elements(自定义标签),本篇介绍使用 CustomElem ...