3 回答

TA貢獻1993條經驗 獲得超6個贊
我遇到了同樣的問題,所以我使用嵌入式參數編寫擴展解決方案
@Query("from PartPrice where "
+ "customer in :#{#customers} and "
+ "( (:#{#suppliers == null || #suppliers.size() == 0} = true and supplier is null) or (:#{#suppliers != null && #suppliers.size() > 0} = true and supplier in :#{#supplier}) ) and "
+ " productIdentifier.manufacturerId = :#{#productIdentifier.manufacturerId} and productIdentifier.productNumber = :#{#productIdentifier.productNumber} and "
+ " ( (:#{#isAbsPrice} = true and abs_price is not null) or (:#{#isAbsPrice} = false and abs_price is null) ) "
+ " and (validUntil is null or validUntil >= :#{#fromDate}) and (:#{#untilDate == null} = true or validFrom <= :#{#untilDate}) ")
其中供應商可為空、為空或包含值,而 productIdentifier 是嵌入的 id,其中包含 productNumber 和制造商 ID 傳遞為
@Param("productIdentifier") ProductIdentifier productIdentifier
間隔也是有效的,從 fromDate 到 null(永遠)或 untilDate。
添加回答
舉報