【Spring Data JPA】JPA 常用查询函数


前言

函数查询的表格参考了官网的 2.7.3 版本的文档,JPA 的这种函数式查询方法改动不大,如果想知道更多的复杂查询,可以参考这篇文章
【Spring Data JPA】基于 JpaRepository 增删改查

官方文档地址
Spring Data JPA 2.7.3官方文档


函数查询表格

关键字关键字意思函数写法SQL 写法
Distinctdistinct 去重findDistinctByLastnameAndFirstnameselect distinct …​ where x.lastname = ?1 and x.firstname = ?2
Andand 关联findByLastnameAndFirstname… where x.lastname = ?1 and x.firstname = ?2
Oror 或者findByLastnameOrFirstname… where x.lastname = ?1 or x.firstname = ?2
Isis 是(与Equals一样)findByFirstname
findByFirstnameIs
… where x.firstname = ?1
Equals等于findByFirstname
findByFirstnameEquals
… where x.firstname = ?1
Betweenbetween 之间findByStartDateBetween… where x.startDate between ?1 and ?2
LessThanlessThan 小于(<)findByAgeLessThan… where x.age < ?1
LessThanEquallessThanEqual 小于等于(<=)findByAgeLessThanEqual… where x.age <= ?1
GreaterThangreaterThan 大于(>)findByAgeGreaterThan… where x.age > ?1
GreaterThanEqualgreaterThan 大于等于(>=)findByAgeGreaterThanEqual… where x.age >= ?1
After大于(一般用在时间)findByStartDateAfter… where x.startDate > ?1
Before小于(一般用在时间)findByStartDateBefore… where x.startDate < ?1
IsNull是 nullfindByAgeIsNull… where x.age is null
Null是 nullfindByAgeNull… where x.age is null
IsNotNull不是 nullfindByAgeIsNotNull… where x.age not null
NotNull不是 nullfindByAgeNotNull… where x.age not null
Like模糊查询findByFirstnameLike… where x.firstname like ?1
NotLike不模糊查询findByFirstnameNotLike… where x.firstname not like ?1
OrderBy排序findByAgeOrderByLastnameDesc… where x.age = ?1 order by x.lastname desc
NotnotfindByLastnameNot… where x.lastname <> ?1
Inin 查询findByAgeIn(Collection ages)… where x.age in ?1
NotInnot in 查询findByAgeNotIn(Collection ages)… where x.age not in ?1
True是 truefindByActiveTrue()… where x.active = true
False是 falsefindByActiveFalse… where x.active = false
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值