我在数据表中有一列,其中有多选过滤器选项,我甚至可以为一列选择五到六个值并进行搜索
Select * from abc
where dept in ('bfs','textile','hr','admin')
我写了一个类似下面的条件查询:
public class Specification implements Specification<Filter>{
private Filter filter;
public Specification(Filter filter) {
super();
this.filter = filter;
}
public Predicate toPredicate(Root<Filter > root, CriteriaQuery<?> cq,
CriteriaBuilder cb) {
Predicate p = cb.conjunction();
if (filter.getTitle() != null) {
p.getExpressions()
.add(cb.equal(root.get("title"), filter.getTitle()));
}
if (filter.getDept() != null) {
p.getExpressions().add(root.get("dept").in(filter.getDept()));
}
return p;
}
}
当我传递如下所示的两个值时,结果集为空。