2017-10-17 209 views
1
@Query(value = "Select f from Documents f " + 
     "RIGHT JOIN f.documentStatus ds " + 
     "where f.billingAccount.accountId in :billingAccountIdList " + 
     " and ds.statusCode in :paymentStatuses" + 
     " and f.paymentDate < :paymentDate") 
List<FinancialDocumentEntity> getFinancialDocumentsOverdue(@Param("billingAccountIdList")List<String> billingAccountIdList, 
                  @Param("paymentStatuses") List<String> paymentStatuses, 
                  @Param("paymentDate") Date paymentDate); 

我有类似上面的查询。如果查询方法为null或为空,可以跳过搜索参数例如@Param("paymentStatuses")如何在@Query中跳过@Param如果在Spring数据中为null或为空JPA

+1

的可能的复制[春季数据 - 忽略的参数,如果它有一个空值(https://stackoverflow.com/questions/43780226/spring -data-ignore-parameter-if-it-has-a-null-value) – araknoid

回答

6

尝试改变

" and ds.statusCode in :paymentStatuses" 

" and (:paymentStatuses is null or ds.statusCode in :paymentStatuses)" 
+0

这是神奇的:) – Ekrem

相关问题