我有一个简单的示例:查找所有售罄的商品。
项目具有initialQuantity和soldQuantity整数字段。(由于某种原因,我需要存储initialQuantity)
我正在尝试做类似的事情:
builder = new BooleanBuilder();
Predicate predicate = builder.and(item.initialQuantity.eq(item.soldQuantity)).getValue();
Iterable<Item> iterable = itemRepository.findAll(predicate);
但是它没有按预期返回。 “ .eq()”看起来像是一个整数,而不是Path <>
首先声明它:
JPAQueryFactory query = new JPAQueryFactory(em);
BooleanBuilder booleanBuilder = new BooleanBuilder();
QCreditRequest creditRequest = QCreditRequest.creditRequest;
然后,您可以包括您的业务逻辑,例如:
booleanBuilder.and(creditRequest.customer.in(dataRequest.getCustomerListToSearchFor()));
booleanBuilder.and(creditRequest.creditRequestId.eq(dataRequest.getCreditRequestId()));
如果(StringUtils.isNotBlank(dataRequest.getProductId()))booleanBuilder.and(creditRequest.product.productId.eq(dataRequest.getProductId()));
finally return the result, mapped to your 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());