递归查询ztree树

控制层

@GetMapping
public ResponseServer queryType() {
List> treeData = typeService.queryType();
return ResponseServer.success(treeData);
}

service:

@Override
public List> queryType() {
    List list = typeDao.queryTypeTree();
    return getTreeList(0, list);
}

private List> getTreeList(Integer pid, List list) {
List> treeList = new ArrayList>();
list.forEach(type -> {
Map map = null;
if (pid.equals(type.getPid())) {
map = new HashMap<>();
map.put(“id”, type.getId());
map.put(“name”, type.getName());
map.put(“pid”, type.getPid());
map.put(“children”, getTreeList(type.getId(), list));
}
if (map != null) {
treeList.add(map);
}
});
return treeList;
}

你可能感兴趣的:(spring,maven,java,spring)