我想根据金额范围对数据库数据进行搜索,有一些金额项也是负数。但无论有什么迹象,我都想使用 javax.persistence.criteria 将我的标准应用于实际金额。
例如查询输入:1 到 100 之间
预期输出:-99 ,-10 , 33 ,90 100
有人可以指导我吗?
最佳答案
SQL查询:
select * from table where abs(cast(amount as decimal(10,2))) between 1 and 700
条件查询:
final List<Predicate> predicates = new ArrayList<>();
Predicate matchPrice = cb.between(cb.abs(trxRoot.get("amount").as(BigDecimal.class)), minPrice, toAmount);
predicates.add(matchPrice);
query.where(predicates.toArray(new Predicate[] {}));
关于Java Criteria 查询金额范围,无论金额符号如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44065700/