本文共 1452 字,大约阅读时间需要 4 分钟。
//获取动态条件的集合 Listlist = new ArrayList (); Long sysUserId = currentUser.getSysUserId(); if (sysUserId != null) { SysUser sysUser = sysUserRepository.findOne(sysUserId); if (sysUser != null) { String groupItemIds = sysUser.groupItemIds(); if (groupItemIds != null && !groupItemIds.isEmpty()) { String[] str = StringUtils.split(groupItemIds,","); for (String s : str) { if (s != null && !s.isEmpty() && s != "") { list.add(Long.valueOf(s)); } } } } }
//封装Specification查询条件 Specificationspec = (root, query, cb) -> { List predicates = new ArrayList (); List preList = new ArrayList (); if (list != null && list.size()>0) { preList.add(root. get("groupItemId").in(list)); } if (sysUserId != null) { Predicate predicate = cb.equal(root.get(Goods_.crtUserId), sysUserId); preList.add(predicate); } Predicate p = cb.or(preList.toArray(new Predicate[preList.size()])); predicates.add(p); if (!predicates.isEmpty()) { return cb.and(predicates.toArray(new Predicate[0])); } else { return null; } }; Page pageresult = goodsRepository.findAll(spec, pageable);
转载地址:http://stiex.baihongyu.com/