• jpa使用


    1、findBy findAllBy的区别

    它们之间没有区别,它们将执行完全相同的查询,当从方法名称派生查询时,Spring Data会忽略All部分。

    唯一需要强调重要的一点是By关键字,其后面的任何内容都被视为字段名称,如 findXXXXXXXXXXXXXByName 实际上==》 findByName

    2、JPA中支持的关键词

    关键字 例子 备注
    And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname = ?2
    Or findByLastnameOrFirstname … where x.lastname = ?1 or x.firstname = ?2
    Is,Equals 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 ages) … where x.age in ?1
    NotIn findByAgeNotIn(Collection 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)
  • 相关阅读:
    精品网站集合
    javascript中关于数组的一些鄙视题
    如何使用github搭建个人博客
    JS复杂数据拆分重组
    如何上传图片到七牛云
    React全家桶+Material-ui构建的后台管理系统
    Javascript继承6:终极继承者----寄生组合式继承
    Javascript继承5:如虎添翼----寄生式继承
    Javascript继承4:洁净的继承者----原型式继承
    Javascript继承3:将优点为我所有----组合式继承
  • 原文地址:https://www.cnblogs.com/hefeng2014/p/16645908.html
Copyright © 2020-2023  润新知