SpringDataJpA或查询 小鱼儿 2021-09-28 23:56 395阅读 0赞 1.需求 进入投诉建议模块的人员列表时候,可以查到客服和售后管家类型的数据 ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW8yOTczMjg_size_16_color_FFFFFF_t_70][] ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW8yOTczMjg_size_16_color_FFFFFF_t_70 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)); \} \}; \} [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW8yOTczMjg_size_16_color_FFFFFF_t_70]: /images/20210923/67ad2993b0d840989553e8eba4276e43.png [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpYW8yOTczMjg_size_16_color_FFFFFF_t_70 1]: /images/20210923/79a07045ff234278bba12d3278d4f113.png
还没有评论,来说两句吧...