本文主要是介绍java 封装easyui tree树结构无限极分类(递归调用),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
public Object queryDiseaseDisCode() {List<Map<String,Object>> treeList =new ArrayList<Map<String,Object>>();//查询第一级分类,即:最顶层节点List<Disease> doseaseList = diseaseDao.selectDisCode();for (int i = 0; i < doseaseList.size(); i++) { Map<String, Object> map = null; Disease disease = (Disease) doseaseList.get(i); if (disease.getParentId().equals(disease.getId)) { map = new HashMap<String, Object>(); //这里必须要将对象疾病的编号disCode、disChineseName转换成tree在页面的显示形式id、text//tree,不是数据表格,没有在页面通过columns转换数据的属性 map.put("id", disease.getId()); //id map.put("text",disease.getText()); //疾病名 map.put("children", createTreeChildren(doseaseList,disease.getId)); } if (map != null) treeList.add(map); } return treeList;}/** * 递归设置疾病树 * @param list * @param fid * @return */ private List<Map<String, Object>> createTreeChildren(List<Disease> list, String fid) {Map<String, Object> pdata = new HashMap<String, Object>();pdata.put("id", fid);//根据父节点Id查询该父节点下所有的子节点List<Disease> childrenList = diseaseDao.selectDisChildCode(pdata);List<Map<String, Object>> childList = new ArrayList<Map<String, Object>>(); for (int j = 0; j < childrenList.size(); j++) { Map<String, Object> map = null; Disease treeChild = (Disease) childrenList.get(j); if (treeChild.getParentId().equals(fid)) { map = new HashMap<String, Object>(); //这里必须要将对象角色的id、name转换成tree在页面的显示形式id、text //tree,不是数据表格,没有在页面通过columns转换数据的属性 map.put("id", treeChild.getId()); //id map.put("text",treeChild.getText()); //疾病名map.put("children", createTreeChildren(childrenList, treeChild.getId())); } if (map != null) childList.add(map); } return childList; }
实体类:/** id*/private Integer id;/** 节点名称*/private String text;/**父亲Id*/private String parentId;
给出get,set方法
sql:
SELECT a.disCode,a.disChineseName,b.fatherCode AS parentId
FROM disease a
LEFT JOIN diseaseRelation b
ON a.disCode = b.disCode
WHERE b.fatherCode = b.disCode
前台jsp:
<script type="text/javascript">var base = "${pageContext.request.contextPath}";$(document).ready(function(){$('#tree').tree({ url: base+"/gene/queryGene.do",}); });</script></head><body><ul id="tree" class="easyui-tree"></ul>
</body>
注意:必须是 id,text 否则easyui tree解析不了
这篇关于java 封装easyui tree树结构无限极分类(递归调用)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!