@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例如@Param("paymentStatuses")
?
答案 0 :(得分:8)
尝试更改
" and ds.statusCode in :paymentStatuses"
进入
" and (:paymentStatuses is null or ds.statusCode in :paymentStatuses)"
答案 1 :(得分:1)
尝试更改
" and ds.statusCode in :paymentStatuses"
进入
" and (COALESCE(:paymentStatuses, null) is null or ds.statusCode in :paymentStatuses)"
此解决方案适用于空列表,空列表以及项目为1或更多的列表。