Spring JPA Data “OR” query

后端 未结 2 1817
甜味超标
甜味超标 2021-02-18 23:02

I am using Spring Data JPA and trying to add a query to my repository. I was trying to just build the query without the @Query annotation like:

List         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-18 23:53

    Well, you are very close. To do this without @Query the In or IsIn keyword can be used(not sure whether these keywords were supported at the time the question was asked):

    List findByTypeAndStateInAndStartDateBetween(Type type, Collection states, Date startDate, Date endDate);
    

    In and NotIn also take any subclass of Collection as parameter as well as arrays or varargs. For other syntactical versions of the very same logical operator check Repository query keywords.

    This will suffice your need of passing any number of states for the OR criteria.

    Reference: Table 4. Supported keywords inside method names in Query creation docs

提交回复
热议问题