JPA 的查询,JPA 根据方法名字查询详细介绍
摘自:https://www.sojson.com/blog/295.html
根据方法名字生成SQL语句(根据方法名查询)。
public interface UserRepository extends Repository<User, Long> {List<User> findByEmailAddressAndLastname(String emailAddress, String lastname);}
我们将使用JPA criteria
API
创建一个查询,但本质上这转换为以下查询:
select u from User u where u.emailAddress = ?1 and u.lastname = ?2
Spring Data JPA 将执行属性检查并遍历属性表达式中描述的嵌套属性。下面是 JPA 支持的关键字的概述,以及包含该关键字的方法的本质含义。
SQL关键词想细介绍
关键词 | Demo | JPQL 语句片段 |
---|---|---|
And | findByLastnameAndFirstname | … where x.lastname = ?1 and x.firstname = ?2 |
Or | findByLastnameOrFirstname | … where x.lastname = ?1 or x.firstname = ?2 |
Is,Equals |
findByFirstname, findByFirstnameIs, findByFirstnameEquals |
… where x.firstname = ?1 |
Between | findByStartDateBetween | … where x.startDate between ?1 and ?2 |
LessThan | findByAgeLessThan | … where x.age < ?1 |
LessThanEqual | findByAgeLessThanEqual | … where x.age ⇐ ?1 |
GreaterThan | findByAgeGreaterThan | … where x.age > ?1 |
GreaterThanEqual | findByAgeGreaterThanEqual | … where x.age >= ?1 |
After | findByStartDateAfter | … where x.startDate > ?1 |
Before | findByStartDateBefore | … where x.startDate < ?1 |
IsNull | findByAgeIsNull | … where x.age is null |
IsNotNull,NotNull | findByAge(Is)NotNull | … where x.age not null |
Like | findByFirstnameLike | … where x.firstname like ?1 |
NotLike | findByFirstnameNotLike | … where x.firstname not like ?1 |
StartingWith | findByFirstnameStartingWith | … where x.firstname like ?1 (parameter bound with appended %) |
EndingWith | findByFirstnameEndingWith | … where x.firstname like ?1 (parameter bound with prepended %) |
Containing | findByFirstnameContaining | … where x.firstname like ?1 (parameter bound wrapped in %) |
OrderBy | findByAgeOrderByLastnameDesc | … where x.age = ?1 order by x.lastname desc |
Not | findByLastnameNot | … where x.lastname <> ?1 |
In | findByAgeIn(Collection<Age> ages) | … where x.age in ?1 |
NotIn | findByAgeNotIn(Collection<Age> age) | … where x.age not in ?1 |
True | findByActiveTrue() | … where x.active = true |
False | findByActiveFalse() | … where x.active = false |
IgnoreCase | findByFirstnameIgnoreCase | … where UPPER(x.firstame) = UPPER(?1) |
JPA 的查询,JPA 根据方法名字查询详细介绍相关推荐
- android飞行模式开启wifi,手机在飞行模式下怎么使用WiFi? 飞行模式下开启WiFi的方法图文教程详细介绍[多图]...
类型: 大小: 评分: 平台: 标签: 手机在飞行模式下怎么使用WiFi?相信很多朋友都还不太清楚吧?没关系,下面是友情小编搜集相关资料整理出来的手机在飞行模式下开启WiFi的方法图文教程详细介绍,希 ...
- bowtie 加mn标签_Bowtie2使用方法与参数详细介绍 - Public Library of Bioinformatics
Bowtie2 使用方法与参数详细介绍 - Public Library of Bioinformatics 懒人必看 Bowtie2 -q --phred33 --sensitive --end-t ...
- Spring JPA查询,JPA 根据方法名字查询详细介绍
版权所属:SO JSON在线解析 原文地址:https://www.sojson.com/blog/295.html JPA 的查询有很多丰富的API,基本能满足了所有的基本查询.下面来想细说说支持 ...
- Spring Data JPA 从入门到精通~方法的查询策略的属性表达式
方法的查询策略的属性表达式(Property Expressions) 属性表达式只能引用托管(泛化)实体的直接属性,如前一个示例所示.在查询创建时,已经确保解析的属性是托管实体的属性,但是,还可以通 ...
- Spring Data JPA 从入门到精通~方法的查询策略设置
方法的查询策略设置 通过下面的命令来配置方法的查询策略: @EnableJpaRepositories(queryLookupStrategy= QueryLookupStrategy.Key.CRE ...
- mysql like 贪婪匹配_mysql模糊查询like与REGEXP的使用详细介绍
前言 在mysql中实现模糊查询的有like和regexp.本文通过实例代码给大家详细介绍这两者的使用方法,下面来跟着小编一起学习学习吧. like模式 like意思是长得像,有两个模式:_和% _表 ...
- MyBatis查询结果resultType返回值类型详细介绍
一.返回一般数据类型 比如要根据 id 属性获得数据库中的某个字段值. mapper 接口: // 根据 id 获得数据库中的 username 字段的值String getEmpNameById(I ...
- 如何服务器上查找nginx网站目录下,查看nginx安装目录和版本的多种方法、命令详细介绍...
Nginx安装目录在哪儿,版本时多少?有时候我们接受了一个别人配置的Nginx Web服务器,首先想确认这些基本信息.其实可以查看Nginx安装目录和安装版本的方法/命令有好多种.(注意:以下命令有的 ...
- Bowtie2使用方法与参数详细介绍
bowtie 短序列比对工具详解 常见的短序列比对工具有很多,如fasta.blast.bowtie.shrimp.soap等.每个工具都有其自身的优点,但同时也具备了一些缺点.权衡利弊,我选择bow ...
最新文章
- iOS开发UI篇—UITableviewcell的性能优化和缓存机制
- SharePoint Error - An unrecognized HTTP response was received when attempting to crawl this item
- C++ string类型占几个字节
- python画出的雷达图效果-PYTHON绘制雷达图代码实例
- MYSQL:子查询关键字 ANY/SOME/IN/ALL
- 揭示垃圾收集暂停的时间长度
- js数组再倒数第二个添加元素_归纳JS中数组的使用(一)元素新增和删除
- python中superclass是什么_深度解析并实现python中的super(转载,好文)
- 构建自己的PHP框架(MVC)
- ASP 中常见的错误 80004005 信息
- Windows任务管理器
- linux设置定时重启任务
- 膜拜NFC解锁(靠近即开锁)
- java导出数据库_如何在Java中从整个数据库导出数据?
- 30个专业配色网站, 让你配色从此更专业
- RxSwift+Moya之项目实战
- Qlikview脚本生成日历表
- 度量学习DML之MoCO
- 英特尔i5 1240H
- Java游戏脚本实现