How to skip @Param in @Query if is null or empty in Spring Data JPA

后端 未结 2 1231
逝去的感伤
逝去的感伤 2021-01-18 08:39
@Query(value = \"Select f from Documents f \" +
        \"RIGHT JOIN f.documentStatus ds \" +
        \"where f.billingAccount.accountId  in :billingAccountIdList \"         


        
2条回答
  •  梦毁少年i
    2021-01-18 08:58

    Try changing

    " and ds.statusCode in :paymentStatuses"
    

    into

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

    This solution will work for the empty list, null list, and a list with items 1 or more.

提交回复
热议问题