我的情况是,当我从 Primefaces 的 selectCheckboxMenu 中选择元素时,我选择的元素之间应该有 OR 。如果我
代码
List<Predicate> predicates = new ArrayList<Predicate>();
Predicate[] predArray = new Predicate[predicates.size()];
Predicate finalQuery;
columnName.forEach(name -> {
if (name.equals("city")) {
finalQuery = cb.or(predicates.toArray(predArray));
predicates.add(finalQuery);
cq.where(finalQuery);
} else {
predicates.toArray(predArray);
cq.where(predArray);
}
});
如果我先选择某个列然后选择复选框,我的方案可以正常工作,但是当我第一次选择复选框然后再选择另一列时,我就失败了。
这是调试的SQL;
select user1_.id as col_0_0_, user1_.login as col_1_0_, user1_.first_name as col_2_0_, user1_.last_name as col_3_0_, user1_.day_of_birth as col_4_0_, userdto0_.district as col_5_0_, userdto0_.city as col_6_0_ from userdto userdto0_ inner join user user1_ on userdto0_.id=user1_.id where (lower(userdto0_.city) like ?) and (lower(userdto0_.city) like ?) and (lower(TO_CHAR(cast(user1_.id as varchar(255)))) like ?) order by user1_.id asc
很抱歉,如果这个问题很愚蠢,但我对这些问题不熟悉。