Query creation

Generally the query creation mechanism for JPA works as described in Query methods. Here’s a short example of what a JPA query method translates into:

Example 43. Query creation from method names
public interface UserRepository extends Repository<User, Long> {    List<User> findByEmailAddressAndLastname(String emailAddress, String lastname); }

We will create a query using the JPA criteria API from this but essentially this translates into the following query:select u from User u where u.emailAddress = ?1 and u.lastname = ?2. Spring Data JPA will do a property check and traverse nested properties as described in Property expressions. Here’s an overview of the keywords supported for JPA and what a method containing that keyword essentially translates to.

Table 4. Supported keywords inside method names
Keyword Sample JPQL snippet

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 query 基本语法解释的更多相关文章

  1. 20191217-关于JPA @Query查询数据一直为空,直接在数据库里执行SQL则可以查出来

    20191217-关于JPA @Query查询数据一直为空,直接在数据库里执行SQL则可以查出来 前提:数据库中查询,由于在视图中无主键概念,只是在代码中由逻辑主键.结果:数据中作为逻辑主键中有个字段 ...

  2. 【Spring Data 系列学习】Spring Data JPA @Query 注解查询

    [Spring Data 系列学习]Spring Data JPA @Query 注解查询 前面的章节讲述了 Spring Data Jpa 通过声明式对数据库进行操作,上手速度快简单易操作.但同时 ...

  3. spring data jpa @query的用法

    @Query注解的用法(Spring Data JPA) 参考文章:http://www.tuicool.com/articles/jQJBNv . 一个使用@Query注解的简单例子 @Query( ...

  4. JPA query between的多种方式(mongodb为例)

    背景 JPA+MongoDB查询,给定一段时间范围查询分页结果,要求时间范围包含. Page<Log> findByCtimeBetweenOrderByCtime( LocalDateT ...

  5. jpa @Query()参数设置,:冒号方式、?NO.问号方式、实体类对象参数设置

    一.service层事务(update/delete) @Transactional(rollbackFor = Exception.class) 二.@Query()参数设置 ?x  和:XX不能混 ...

  6. spring jpa @Query中使用in

    @Modifying @Query("delete from SmTenant s where s.id in ?1") void deleteByIds(List<Long ...

  7. JSON.stringify 语法解释

    行为:此函数的作用主要是串行化对象. 或许有些人是过敏的字系列.我非常理解easy.是对象的类型转换成字符串类型(或者更确切的说是json类型的).就这么简单.打个例如说,你有一个类,那么你能够通过这 ...

  8. MySql最土的语法解释使用一。

    create database namedb charset utf8;解释:创建一个数据库 namedb改成你的数据库名字,charset是字符集的意思 utf8代表数据库支持中文字符集.必须分号结 ...

  9. Python的方法和语法解释

    ---------------------------------------------------------------------------------------------------- ...

随机推荐

  1. 【转】IOS AutoLayout详解(三)用代码实现(附Demo下载)

    转载自:blog.csdn.net/hello_hwc IOS SDK详解 前言: 在开发的过程中,有时候创建View没办法通过Storyboard来进行,又需要AutoLayout,这时候用代码创建 ...

  2. JAVA开发环境 - 环境变量及配置

    JDK是什么?JRE是什么? JRE(Java Runtime Environment):Java运行环境: JDK(Java Development Kit):Java开发工具包,里面已经包含JRE ...

  3. java基础之抽象类与接口的区别

    在学习java的过程中,或者是在找工作笔试或面试的时候,如果你是java岗位,那么抽象类与接口的区别无疑是一个大热点,是各大公司都想要考的一个小知识点,下面是我为了9月份秋招自己总结的,若有不对的地方 ...

  4. linux指令备份

    ls -a 显示隐藏文件 cd 回到当前用户的目录 /home/ubuntu touch 创建文件 cat Hello.javamore/less Hello.java分页显示 grep root / ...

  5. Sqoop import加载HBase案例详解

    简单写一下如何将订单表sqoop到hbase表中的步骤. 下表: 1.通过hbase shell 打开hbase. 2.创建一个hbase表 create 'so','o' 3.将so表的数据导入到h ...

  6. oc 怎么接收NSSting字符的方法

    ]; //使用一个缓冲区 NSLog(@"请输入一个字符串:"); scanf("%s",buffer); NSString * str = [NSString ...

  7. Unable to load configuration. - bean - jar: ....struts2-core-2.1.8.1.jar!/struts-default.xml:47:178

    摘录的异常代码: 2013-12-14 22:42:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error严重: Dis ...

  8. php学习小技巧

    1.print_r可打印数组 <?php echo '<p class="ajax">This paragraph was loaded with AJAX.&l ...

  9. 【实习记】2014-08-10(上)代码跟踪git的想法+归并排序的debug过程

        (冒泡,选择,插入,希尔,快速,归并,堆排)周末加班学习C++,打算用C++写七大经典排序代码.发现3个月前自己写的七大经典排序代码(C Language)突然运行出错. Makefile内容 ...

  10. IPython,让Python显得友好十倍的外套——windows XP/Win7安装详解

        前言 学习python,官方版本其实足够了.但是如果追求更好的开发体验,耐得住不厌其烦地折腾.那么我可以负责任的告诉你:IPython是我认为的唯一显著好于原版python的工具.   整理了 ...