我有一个简单的例子:查找所有售罄的物品。物料具有initialQuantity和soldQuantity整数字段。(由于某种原因,我需要存储initialQuantity)我正在尝试做类似的事情:builder = new BooleanBuilder();Predicate predicate = builder.and(item.initialQuantity.eq(item.soldQuantity)).getValue();Iterable<Item> iterable = itemRepository.findAll(predicate);但它不会按预期返回。 “ .eq()”看起来像是一个整数,而不是Path (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 首先声明:JPAQueryFactory query = new JPAQueryFactory(em);BooleanBuilder booleanBuilder = new BooleanBuilder();QCreditRequest creditRequest = QCreditRequest.creditRequest;然后,您可以包括您的业务逻辑,例如:booleanBuilder.and(creditRequest.creditRequestId.eq(dataRequest.getCreditRequestId()));if (StringUtils.isNotBlank(dataRequest.getProductId())){ booleanBuilder.and(creditRequest.product.productId.eq(dataRequest.getProductId()));}最后返回结果,映射到您的DTO:return new HashSet<>( query .select( Projections.constructor( APResponse.class, creditRequest.creditRequestId, creditRequest.creditRequestDate, creditRequest.product.productId, creditRequest.creditRequestComment)) .from(creditRequest) .innerJoin(creditRequest.product, product) .innerJoin(creditRequest.status, creditRequestStatus) .where(booleanBuilder) .fetch()); (adsbygoogle = window.adsbygoogle || []).push({}); 09-27 15:09