java - 需要使用 BooleanBuilder 连接多个数组值
问题描述
尝试连接看起来像伪代码的数组值:
SELECT * FROM (fiscalYear = 2017 OR fiscalYear = 2018)
AND (accountingPeriod = 2017 OR accountingPeriod = 2018)
当前输出为:
SELECT * FROM fiscalYear = 2017 OR fiscalYear = 2018
我尝试过使用 BooleanBuilder 的多个连接,并且还围绕所有返回创建了一个大循环。没有任何效果。
@Service
public class FilterService {
@Autowired
SpendRepository spendRepository;
public Iterable<Spend> filterSpendingByAll(Integer[] fiscalYear, Integer[] accountingPeriod, String[] department, String[] apCategory,
String[] jurisdiction, String[] functionName, String[] vendorId) {
QSpend spend = QSpend.spend;
BooleanBuilder builder = new BooleanBuilder();
for (int i = 0; i < fiscalYear.length; i++){
builder.or(spend.fiscalYear.eq(fiscalYear[i]));
}
for (int i = 0; i < accountingPeriod.length; i++){
builder.or(spend.accountingPeriod.eq(accountingPeriod[i]));
}
for (int i = 0; i < department.length; i++){
builder.or(spend.department.like("%" + department[i] + "%"));
}
for (int i = 0; i < apCategory.length; i++){
builder.or(spend.apCategory.like("%" + apCategory[i] + "%"));
}
for (int i = 0; i < jurisdiction.length; i++){
builder.or(spend.jurisdiction.like("%" + jurisdiction[i] + "%"));
}
for (int i = 0; i < functionName.length; i++){
builder.or(spend.functionName.like("%" + functionName[i] + "%"));
}
for (int i = 0; i < vendorId.length; i++){
builder.or(spend.vendorId.like("%" + vendorId[i] + "%"));
}
for (int i = 0; i < vendorId.length; i++){
builder.or(spend.vendorId.eq(vendorId[i]));
}
return this.spendRepository.findAll(builder);
}
}
实际结果是:
SELECT * FROM fiscalYear = 2017 OR fiscalYear = 2018
预期结果是:
SELECT * FROM (fiscalYear = 2017 OR fiscalYear = 2018)
AND (accountingPeriod = 2017 OR accountingPeriod = 2018)
解决方案
推荐阅读
- selenium - 在 Selenium IDE 中打印数组元素
- c# - 如何使用 mvvm 在字符串属性中使用方法?
- javascript - 新标签 selenium + js
- javascript - 不确定我是否正确创建了进度加载/错误功能
- scikit-learn - 设置 scikit-learn GridSearchCV 的时间限制
- python-3.x - [[0]*m]*n 和 [[0 for i in range(0,m)] for j in range(0,n)] 之间的差异
- python - 使用 pyinstaller 将 .json 文件添加到 exe 文件
- ms-word - 如何通过链 pandoc -> sphinx 将 Word 文档转换为 html 文件并保留文档代码示例的选项卡
- python - 是否有使用熊猫限制旋转数据行数的功能?
- javascript - 如何在角度 7 中使用 ngFor 循环动态嵌套数组