JPA查询关键字

JPA查询关键字

Spring Data JPA使用方法名可解决大部分的查询问题,但是也存在不能解决所有问题,以下是方法名中支持的关键字:

关键字 简单示例 JPQL片段示例
AND findByLastNameAndFirstName WHERE Entity.lastName = ?1 AND Entity.firstName = ?2
IsNull findByAddressIsNull WHERE Entity.address is NULL
IsNotNull readByAddressIsNotNull WHERE Entity.address NOT NULL
NotNull readByAddressNotNull WHERE Entity.address NOT NULL
OR readByLastNameOrFirstName WHERE Entity.lastName = ?1 OR Entity.firstName = ?2
Between getByStartDateBetween WHERE Entity.startDate BETWEEN ?1 AND ?2
LessThan findByAgeLessThan WHERE Entity.age < ?1
GreaterThan readByAgeGreaterThan WHERE Entity.age > ?1
After只作用在时间 findByStartDateAfter WHERE Entity.startDate > ?1
Before只作用在时间 findByStartDateBefore WHERE Entity.startDate < ?1
LessThanEqual findByAgeLessThenEqual WHERE Entity.age <= ?1
GreaterThanEqual readByAgeGreaterThenEqual WHERE Entity.age >= ?1
Is findByLastNameIs WHERE Entity.lastName = ?1
Equal getByFirstNameEqual WHERE Entity.firstName = ?1
Like findByNameLike WHERE Entity.name LIKE ? 不包括'%'符号
Not Like findByNameNotLike WHERE Entity.name not like ?1 不包括'%'符号
StartingWith readByNameStartingWith WHERE Entity.name like ‘?1%’条件以'%'符号结尾
EndingWith readByName EndingWith WHERE Entity.name like ‘%?1’条件以'%'符号开头
Containing getByNameContaining WHERE Entity.name like ‘%?1%’ 包含'%'符号
OrderBy findByAgeOrderByAddressDesc WHERE Entity.age = ? Order By Entity.address DESC
Not readByAgeNot WHERE Entity.age <> ?1 不等于
In findByNameIn(Collection name) WHERE Entity.name IN (?1 ,?2, ?3)
NotIn getByNameNotIn(Collection name) WHERE Entity.name NOT IN (?1 ,?2, ?3)
True readByFloagTrue() WHERE Entity.floag = true
False readByFloagFalse() WHERE Entity.floag = false
IgnoreCase findByNameIgnoreCase WHERE UPPER(Entity.Name) = UPPER(?1)

你可能感兴趣的:(SpringBoot)