【发布时间】:2016-08-15 07:31:03
【问题描述】:
我有如下查询
select sum(qty)... from table where productname = 'Pepsi' group by product.
我在PathBuilderQueryDSL下面创建了Spring代码:-
PathBuilder<Stock> entityPath = new PathBuilder<Stock>(Stock.class, "stock");
BooleanPath path = entityPath.getBoolean("productname");
BooleanExpression wherecondition = path.eq("pepsi");
NumberPath<Double> path = entityPath.getNumber("qty", Double.class);
NumberExpression<Double> sumfunction= path.castToNum(Double.class).sum();
我正在使用 JPA 存储库来获取如下可分页数据:-
Page<Stock> page = stockRepository.findAll(wherecondition,pageable);
我不知道如何将上面的sumfunction 与 JPA 存储库一起使用。因为我不能结合BooleanExpression 和NumberExpression
【问题讨论】:
-
使用查询 dsl 的任何具体原因?
-
因为查询是动态的,基于来自前端的过滤器
-
这是唯一的条件 productname = 'Pepsi' 还是您拥有的任何其他条件?我假设 productname 的值是动态的,即 Pepsi 可能会根据用户选择而变化。
标签: java spring spring-data-jpa querydsl