3 回答
TA贡献1993条经验 获得超5个赞
我遇到了同样的问题,所以我使用嵌入式参数编写扩展解决方案
@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。
添加回答
举报