Deprecated: Constant PDO::MYSQL_ATTR_USE_BUFFERED_QUERY is deprecated since 8.5, use Pdo\Mysql::ATTR_USE_BUFFERED_QUERY instead in /www/wwwroot/www.1998123.xyz/var/Typecho/Db/Adapter/Pdo/Mysql.php on line 71
JPA查询缩减写法 - 98123_学习与记录

下表把 jpa 做的各种查询规范都列出来了。 如果要做其他相关查询,按照表格中的规范设计接口方法即可。


关键词 举例 生成的JPQL 语句片段
And findBy**Lastname**And**Firstname** … where x.lastname = ?1 and x.firstname = ?2
Or findBy**Lastname**Or**Firstname** … where x.lastname = ?1 or x.firstname = ?2
Is,Equals findBy**Firstname**,
findBy**Firstname**Is,
findBy**Firstname**Equals
… where x.firstname = ?1
Between findBy**StartDate**Between … where x.startDate between ?1 and ?2
LessThan findBy**Age**LessThan … where x.age < ?1
LessThanEqual findBy**Age**LessThanEqual … where x.age ⇐ ?1
GreaterThan findBy**Age**GreaterThan … where x.age > ?1
GreaterThanEqual findBy**Age**GreaterThanEqual … where x.age >= ?1
After findBy**StartDate**After … where x.startDate > ?1
Before findBy**StartDate**Before … where x.startDate < ?1
IsNull findBy**Age**IsNull … where x.age is null
IsNotNull,NotNull findBy**Age**(Is)NotNull … where x.age not null
Like findBy**Firstname**Like … where x.firstname like ?1
NotLike findBy**Firstname**NotLike … where x.firstname not like ?1
StartingWith findBy**Firstname**StartingWith … where x.firstname like ?1 (parameter bound with appended %)
EndingWith findBy**Firstname**EndingWith … where x.firstname like ?1 (parameter bound with prepended %)
Containing findBy**Firstname**Containing … where x.firstname like ?1 (parameter bound wrapped in %)
OrderBy findBy**Age**OrderBy**Lastname**Desc … where x.age = ?1 order by x.lastname desc
Not findBy**Lastname**Not … where x.lastname <> ?1
In findBy**Age**In(Collection ages) … where x.age in ?1
NotIn findBy**Age**NotIn(Collection age) … where x.age not in ?1
True findBy**Active**True() … where x.active = true
False findBy**Active**False() … where x.active = false
IgnoreCase findBy**Firstname**IgnoreCase … where UPPER(x.firstame) = UPPER(?1)

标签: none

添加新评论