无极限树结构

Java获取树型结构数据:

@RequestMapping("getClassifyJsonTree")

public @ResponseBody String getClassifyJsonTree(String id) {
Map m = new HashMap();
m.put("Data", subClassifyTree(id));
String str = JSON.toJSONString(m);
str = str.replace("Data", "Child");
return str;
}


/***
* 获取分类树节点信息 迭代实现
* @return
*/
private List> subClassifyTree(String parentId) {
List classifyList;
if (parentId != null && StringUtils.isNotBlank(parentId)) {
classifyList = service.getDirectReportClassifyById(parentId);
} else {
classifyList = service.getTopReportClassify(); 
}


List> classify = new ArrayList>();
for (ReportClassify rc : classifyList) {
List> subClassify = null;
if (service.getDirectReportClassifyCount(rc.getId()) > 0) {
subClassify = subClassifyTree(rc.getId());
}

Map m = new HashMap();
m.put("Id", rc.getId());
m.put("Name", rc.getName());
m.put("Selected", false);
m.put("Child", subClassify);
classify.add(m);
}
return classify;
}

你可能感兴趣的:(无极限树结构)