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 ...
随机推荐
- 转:Entity Framework 5.0 Code First全面学习
Code First 约定 借助 CodeFirst,可通过使用 C# 或Visual Basic .NET 类来描述模型.模型的基本形状可通过约定来检测.约定是规则集,用于在使用 Code Firs ...
- luogu P3356 火星探险问题
本题很简单的费用流问题,有石头的点需要限制,那我们就可以拆点,capacity为1就可以限制,然后cost为-1,直接跑板子就可以了,注意输出的时候找残量网络的反向边
- uniGUI之多页面框架(16)
效果图: 左边的树 的树结点 ,通过 结点名 与 右 侧TabSheet名 一致时,显示 相关页面. 这是相关 源代码 procedure TMainForm.UniFormCreate(Sender ...
- Lucene_solr
1.总结 https://pan.baidu.com/s/1pMAWk0z 密码:ekhx 2.代码 https://pan.baidu.com/s/1nxmTWy1 密码:65ec 3.资料 ...
- 隧道技术(Tunneling)
隧道技术及其应用 隧道技术(Tunneling)是一种通过使用互联网络的基础设施在网络之间传递数据的方式.使用隧道传递的数据(或负载)可以是不同协议的数据帧或包.隧道协议将其它协议的数据帧或包重新封装 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表单:复选框(Checkbox)和单选框(Radio)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Linux系统chmod命令的含义和权限详解
许多喜欢使用chmod命令的用户,对chmod命令的含义和权限仍然不是很清楚,因此在使用的时候对它们造成了一定的麻烦.为了解决这些用户的迷惑,今天小编就和大家一起分享下chmod命令的含义和权限. 对 ...
- 第1节 storm日志告警:1、 - 5、日志监控告警业务需求、代码、集群运行、总结
如何解决短信或者邮件频繁发送的问题:每次发送的时候都先查询数据库记录,看一下有没有给这个人发送消息,上一次发送消息的时间是什么时候,如果发送时间间隔小于半个小时,就不要再发了 ============ ...
- 一、jsp和Servlet基础理论及jstl和EL表达式用法
1.题外话:使用JSP有近一年半的时间了,但是开发量不大.昨天部门突然让做个读取EXCLE文件,然后在前台页面进行展示.并通过点击查看按钮可以对每条明细记录进行跳转后进行详情查看,并按照页面原型进行页 ...
- 剑指offer 把数组排成最小的数 atoi和itoa,pow
pow(x,y)在#include<math.h>文件中,计算x的y次方. C++引入头文件:#include <stdlib.h> 或者 #include <cstdl ...