spring data 接口之 JpaRepository,JpaSpecificationExecutor
2019独角兽企业重金招聘Python工程师标准>>>
package org.zgf.spring.data.dao; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.zgf.spring.data.entity.StudentPO; /** * JpaRepository 继承于 PagingAndSortingRepository 接口, * 由于JpaSpecificationExecutor 并不继承repository 接口,所以它不能单独使用,只能和jpa Repository 一起用 */ public interface IStudentJpaRepository extends JpaRepository<StudentPO, Integer>, JpaSpecificationExecutor<StudentPO> {/** JpaRepository 主要特点,将返回类型 Iterable 转换成了List, 并新增了写方法 * List<T> findAll(); * List<T> findAll(Sort sort); * List<T> findAll(Iterable<ID> ids); * <S extends T> List<S> save(Iterable<S> entities); * void flush(); * <S extends T> S saveAndFlush(S entity); * void deleteInBatch(Iterable<T> entities); * void deleteAllInBatch(); * T getOne(ID id); */ /** JpaSpecificationExecutor 实现了带条件的查询 * T findOne(Specification<T>); * List<T> findAll(Specification<T>); * List<T> findAll(Specification<T>, Sort); * List<T> findAll(Specification<T>, Pageable); * long count(Specification<T>); */ }
测试类
package org.zgf.spring.data.dao; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; import org.zgf.spring.data.base.BaseTest; import org.zgf.spring.data.dao.IStudentJpaRepository; import org.zgf.spring.data.entity.StudentPO; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Path; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.util.List; public class Test_IStudentJpaRepository extends BaseTest {@Autowired private IStudentJpaRepository studentJpaSpecification; @Testpublic void test_findAll() {Specification<StudentPO> specification = new Specification<StudentPO>() {@Override public Predicate toPredicate(Root<StudentPO> root, CriteriaQuery<?> query, CriteriaBuilder cb) {Path path = root.get("id"); Predicate predicate = cb.lt(path, 5); return predicate; }}; List<StudentPO> studentList = this.studentJpaSpecification.findAll(specification); for (StudentPO studentPO : studentList) {System.out.println(studentPO); }} }
转载于:https://my.oschina.net/u/3664884/blog/1789967
spring data 接口之 JpaRepository,JpaSpecificationExecutor相关推荐
- Spring Data Jpa的JpaRepository的getOne()方法查询数据实体时报错could not initialize proxy
问题描述:在使用Spring Data Jpa的JpaRepository的getOne()方法查询数据实体时报以下错误: org.hibernate.LazyInitializationExcept ...
- Spring Data JPA(官方文档翻译)
关于本书 介绍 关于这本指南 第一章 前言 第二章 新增及注意点 第三章 项目依赖 第四章 使用Spring Data Repositories 4.1 核心概念 4.2 查询方法 4.3 定义rep ...
- Spring Data JPA简单使用
Spring Data Jpa 1.JPA简介 JPA的出现主要是为了简化持久层开发以及整合ORM技术,结束Hibernate.TopLink.JDO等ORM框架各自为营的局面.JPA是在吸收现有OR ...
- Spring Data JPA 从入门到精通~JpaRepository介绍
从 JpaRepository 开始的子类,都是 Spring Data 项目对 JPA 实现的封装与扩展.JpaRepository 本身继承 PagingAndSortingRepository ...
- Spring Data JPA 自定义Repository接口与子接口
上篇文章介绍了 Repository接口的使用(Spring Data JPA介绍与Spring的整合),接下来重点掌握 Repository的CrudRepository子接口下的子接口. 在dao ...
- Spring Data JPA 从入门到精通~JpaSpecificationExecutor的使用方法
JpaSpecificationExecutor 源码和 API 我们也可以通过 idea 工具详细看其用法和实现类,JpaSpecificationExecutor 是 Repository 要继承 ...
- Spring Data JPA 从入门到精通~JpaSpecificationExecutor示例
新建两个实体 @Entity(name = "UserInfoEntity") @Table(name = "user_info", schema = &quo ...
- 聊聊Spring Data Auditable接口的变化
为什么80%的码农都做不了架构师?>>> 序 本文主要研究一下Spring Data Auditable接口的变化 1.12.8.RELEASE版本 spring-data-c ...
- Spring Boot与Kotlin使用Spring Data Rest创建HAL风格Restful接口
为什么80%的码农都做不了架构师?>>> REST web服务已成为在web上应用程序集成的首选方式.在其核心中,REST定义了系统由客户端交互的资源组成.这些资源以超媒体驱动 ...
- Spring Data JPA-根据Repository接口关键字生成SQL
Spring Data JPA-根据Repository接口关键字生成SQL JPA支持根据Repository接口中的方法名生成SQL,常用的CRUD都可以实现. 支持的查询方法主题关键字(即前缀, ...
最新文章
- 如何提升深度学习性能?数据、算法、模型一个都不能少
- 【转】高性能前端3-高性能javascript
- day10 in india
- 币安Binance.client can‘t find the module client 解决办法
- git 的 merge 与 no-ff merge 的不同之处
- Android studio设置相机权限,如何强制将“android.permission.CAMERA”权限添加到Codename中的清单中...
- mit许可证_MIT许可证的神秘历史
- 20171108 模拟题 T1
- Windows 拥抱 Android,微软在下怎样的一步棋?
- ArcGIS软件中的坐标系及数据类型的概念
- Activity启动过程(一)AMS
- 数据中心软件漏洞测试,数据中心威胁、漏洞和风险评估
- 面试前你要准备这些东西
- 微信小程序,实现一个简易的新闻网
- matlab自由落体程序,基于MATLAB的自由落体运动仿真.pdf
- ubuntu软件商店提示has install-snap change in progress问题
- php的变量命名规则
- 【T+】删除/取消畅捷通T+软件登录账套后的“查看认证”按钮
- linux怎么清理系统盘垃圾,清理服务器系统盘垃圾,解决系统盘很快就满的问题...
- 微信公众号如何运营才能吸引用户的关注?
热门文章
- 如何将开源项目部分代码作为private放在github上?
- 通过AFNetworking获取服务器时间
- 1734: [Usaco2005 feb]Aggressive cows 愤怒的牛
- 企业级的Java快速开发平台,首选iMatrix平台。
- 黄聪:WordPress默认编辑器可视化切换不见了,非插件导致消失问题
- 自旋锁spin_lock
- 使用OpenCV4Android打开相机
- 为VMware虚拟机内安装的Ubuntu 16.04设置静态IP地址
- live555 RTSP服务器建立及消息处理流程
- L3-015 球队“食物链” (30 分)