Spring JPA findBy 两个或条件

Spring JPA findBy two or conditions

需要有关 Spring JPA 的帮助。假设我想知道谁在收到交通罚单时检查了汽车。这样 licenseNum

  1. citationDate大于checkoutDatecitationDate小于returnDate;或
  2. citationDate 大于 checkoutDatereturnDatenull

目前,

List<SomeEntity> findByLicenseNumAndCheckOutDatetimeBeforeAndReturnDatetimeAfterOrReturnDatetimeIsNullOrderByIdDesc()

正确生成 #1 但生成所有 licenseNumreturnDate null.

如何用 'or' 语句正确编写 spring JPA 语句?

您实际上可以考虑使用 Query 注释,您可以在其中指定自定义查询。 Yon可以选择一个更有意义的方法名并且方便maintain/change.