这里介绍一种笨方法,而不是直接从数据库中过滤。
@RequestMapping(value = "orderTreeData") @ResponseBody @RequiresUser public List<Map<String, Object>> orderTreeData(String excludeCode, String isShowCode) { List<Map<String, Object>> mapList = ListUtils.newArrayList(); ProductTransport productTransport = new ProductTransport(); productTransport.setStatus("0"); List<ProductTransport> list = productTransportService.findList(productTransport); for (int i=0; i<list.size(); i++){ ProductTransport e = list.get(i); // 过滤非正常的数据 Map<String, Object> map = MapUtils.newHashMap(); map.put("id", e.getOrder().getId()); map.put("pId", "0"); map.put("name", e.getOrder().getOrderNum()); map.put("title", e.getOrder().getOrderNum()); // 判断 name 不存在,则添加 if (mapList.stream().noneMatch(d -> d.get("name").equals(e.getOrder().getOrderNum()))) { mapList.add(map); } } return mapList; }