小编典典

如果在Spring Data JPA中为空或为空,如何跳过@Query中的@Param

hibernate

@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);

我有上述查询。是否可以跳过搜索参数,例如@Param("paymentStatuses")在查询方法中是否为null或为空?


阅读 740

收藏
2020-06-20

共1个答案

小编典典

尝试改变

" and ds.statusCode in :paymentStatuses"

进入

" and (:paymentStatuses is null or ds.statusCode in :paymentStatuses)"
2020-06-20