如果在 Spring Data JPA 中为 null 或为空,如何在 @Query 中跳过 @Param [英] How to skip @Param in @Query if is null or empty in Spring Data JPA
本文介绍了如果在 Spring Data JPA 中为 null 或为空,如何在 @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 或为空,可以跳过查询方法中的搜索参数,例如 @Param("paymentStatuses")
?
I have query like above. It is possible to skip searching param for example @Param("paymentStatuses")
in query method if is null or is empty ?
推荐答案
尝试改变
" and ds.statusCode in :paymentStatuses"
进入
" and (:paymentStatuses is null or ds.statusCode in :paymentStatuses)"
这篇关于如果在 Spring Data JPA 中为 null 或为空,如何在 @Query 中跳过 @Param的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文