当前位置: 首页 > 知识库问答 >
问题:

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

戚默
2023-03-14
@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("paymentStatuse")

共有2个答案

山疏珂
2023-03-14

试着改变

" and ds.statusCode in :paymentStatuses"

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

此解决方案适用于空列表、空列表和包含1项或更多项的列表。

白彦
2023-03-14

试着改变

" and ds.statusCode in :paymentStatuses"

" and (:paymentStatuses is null or ds.statusCode in :paymentStatuses)"
 类似资料:
  • 问题内容: 我有上述查询。是否可以跳过搜索参数,例如在查询方法中是否为null或为空? 问题答案: 尝试改变 进入

  • 我试图插入空数据,它必须出错,但它仍然在保存。如果为空,我尝试try/cath和if语句仍然不起作用。有人能建议如何做吗? 此图像中的输出RPCbloom 这个项目是带有GRPC和MyBatis的Spring Boot。

  • 问题内容: 因此,这似乎很简单,我发誓我以前做过,但是出于某种原因,它对我不起作用。 我正在使用并有一个包含约200列的表,如果要向其中插入NULL或空数据,我希望其中约20列默认为0。 这是一个小例子,说明我的表的外观以及我要默认设置为0的列所执行的操作。 因此请注意,我将其设置为问题是,当将空数据传递给它时,出现SQL错误。 我也尝试过将NULL DEFAULT‘0’设置为空,但是当传递空数据

  • 到目前为止,我得到了indexOutOfBoundsException错误

  • 问题内容: 我正在使用JPA,hibernate3。 当没有空值或空值时,此查询就像一个超级按钮。但是 traceEntityVO.getLotNumber(),traceEntityVO.getMfrLocId(),traceEntityVO.getExpDate()的 值可能为null或为空 。 在这种情况下,将针对变量而不是 null 条件来检查值’null’或’‘ 。当我不确定参数值是否为

  • 问题内容: 我看到这是如何加入的String []答案逗号分隔字符串。 但是, 仅 当值不为空时,我才需要util将字符串加入数组中。 最好的方法是什么?无需在String []上循环之前删除。我更喜欢两种方法都可以。 已编辑 例如: 将会: 问题答案: PS:很抱歉使用??接线员-我必须快点做,我在工作。:)