编程语言
首页 > 编程语言> > java-如何在Spring Data JPA中跳过@Query中的@Param是否为空或为空

java-如何在Spring Data JPA中跳过@Query中的@Param是否为空或为空

作者:互联网

@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或为空,可以跳过查询方法中的@paraam(“ paymentStatuses”)参数.

解决方法:

尝试改变

" and ds.statusCode in :paymentStatuses"

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

标签:java,spring,spring-data-jpa,hibernate,jpql
来源: https://codeday.me/bug/20191011/1889117.html