如何用Spring数据查询方式写A And (B Or C)等条件查询?

How to write a query with conditions such as A And (B Or C) with Spring Data query methods?

Spring Data documentation的基础上,很容易做A或B等条件。例子:

List<Person> findByLastnameOrFirstname(String lastname, String firstname);

我想知道如何编写条件为 A And (B Or C) 的查询。类似于以下内容:

List<Person> findByEmailAddressAnd(LastnameOrFirstname)(String emailAddress, String lastname, String firstname);

感谢和问候。

您可以使用 @Query 注释。

@Query("SELECT p FROM Person p WHERE p.emailAddress=:emailAddress AND (p.lastName=:lastName OR p.firstName=:firstName)")
List<Person> findByEmailAddressAnd(LastnameOrFirstname)(String emailAddress, String lastname, String firstname);