我编写了以下 JPQL 查询。在查询中,多个值(男性、女性等)出现在列表中,如性别列表或其他列表。它在控制台中显示一个错误,例如“在需要条件的上下文中指定的非布尔类型的表达式,靠近','”,“。请帮助我。尝试了很多方法来解决。
查询:
@Query("""
SELECT customer_receiver
FROM SubsidyCustomerUserReceiverEntity customer_receiver
WHERE customer_receiver.deleted = false
AND (:isPovertyLineCheck IS NULL OR :isPovertyLineCheck = false OR customer_receiver.isEligible = :isPovertyLineCheck)
AND (:incomeLowerLimit IS NULL OR :incomeUpperLimit IS NULL OR
customer_receiver.receiverGrossHouseholdIncomeAmount BETWEEN :incomeLowerLimit AND :incomeUpperLimit)
AND (:ageLowerLimit IS NULL OR :ageUpperLimit IS NULL OR
customer_receiver.ageYear BETWEEN :ageLowerLimit AND :ageUpperLimit)
AND ((:locationList) IS NULL OR customer_receiver.area IN (:locationList))
AND ((:employmentTypeList) IS NULL OR customer_receiver.employmentType IN (:employmentTypeList))
AND ((:occupationList) IS NULL OR customer_receiver.incomeSourceOrOccupationName IN (:occupationList))
AND ((:genderList) IS NULL OR customer_receiver.gender IN (:genderList))
""")
List<SubsidyCustomerUserReceiverEntity> getEligibleCustomerReceiver(BigDecimal incomeLowerLimit,
BigDecimal incomeUpperLimit, Integer ageLowerLimit, Integer ageUpperLimit, Boolean isPovertyLineCheck,
List<String> locationList, List<EmploymentType> employmentTypeList, List<String> occupationList,
List<String> genderList);
我尝试过调整查询。
有两件事你必须检查。
我已经使用 JpaSpecification 解决了这个问题。谢谢大家的回答。