1.需求
进入投诉建议模块的人员列表时候,可以查到客服和售后管家类型的数据
private Specification<Employee> whereClause(Employee entity) {
return new Specification<Employee>() {
@Override
public Predicate toPredicate(Root<Employee> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
List<Predicate> list = new ArrayList<Predicate>();
Predicate e1 = null;
Predicate e2 = null;
Predicate e3 = null;
if (StringUtils.isNotBlank(entity.getType())) {
String[] str = entity.getType().split(",");
if (str.length == 1) {
e1 = criteriaBuilder.equal(root.get("type").as(String.class), entity.getType());
} else {
e2 = criteriaBuilder.equal(root.get("type").as(String.class), str[0]);
e3 = criteriaBuilder.equal(root.get("type").as(String.class), str[1]);
e1 = criteriaBuilder.or(e2, e3);
}
list.add(e1);
}
Predicate[] p = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(p));
}
};
}