JPA#Interfaces总结
2024-09-05 09:45:28
_开局一张图,内容全靠编
震惊:某小白熟练使用了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
_
_
最新文章
- SQL2008中的Sequence
- jQuery3的新特性
- 【PCB】【项目记录】AWG任意波形产生器
- python---dnspython
- iOS tableviewcell 分割线 偏移和颜色
- CETV面试总结
- 每日学习心得:SharePoint 为列表中的文件夹添加子项(文件夹)、新增指定内容类型的子项、查询列表中指定的文件夹下的内容
- Oracle 11g 中恢复管理器RMAN介绍
- HDU 2767:Proving Equivalences(强连通)
- javaSE第四天
- HTTP常见返回代码(HTTP Status codes)的分类和含义
- shareplex的安装&;&;起停服务(添加新用户)
- vi/vim正则表达式
- 【性能优化】优化笔记之一:图像RGB与YUV转换优化
- HttpWebResponse请求状态代码
- 有一种设计风格叫RESTful
- aix Mysql安装 Oracle官方教程
- URAL 1180. Stone Game (博弈 + 规律)
- 严格模式 (JavaScript)
- [算法] avl树实现
热门文章
- spark aggregateByKey 时 java.lang.OutOfMemoryError: GC overhead limit exceeded
- CentOS6.9安装redis
- Zabbix在Docker中的应用和监控
- three.js的一些介绍
- zookeeper logs is missing zookeeper 日志丢失
- 尝试使用 Visual Studio Online (Cloud IDE)
- css常用设置
- NOI2019 选做
- AngularJs 禁止模板缓存
- 十四 数据库连接池&;DBUtils