/** * 遞歸算法解析成樹形結構 * * @param cid * @return * @author jiqinlin */ public TreeNodeModel recursiveTree(int org_code) { //根據cid獲取節點對象(SELECT * FROM tb_tree t WHERE t.cid=?) MiddleOrgEntity middleOrgEntity = new MiddleOrgEntity(); middleOrgEntity.setTableName(TableConstants.EWX_MIDDEL_ORG); middleOrgEntity.setOrg_code(org_code); middleOrgEntity = (MiddleOrgEntity) commonService.selectOneByExample(middleOrgEntity); TreeNodeModel treeNodeModel = new TreeNodeModel(); treeNodeModel.setOrg_code(org_code); treeNodeModel.setOrg_name(middleOrgEntity.getOrg_name()); //TreeNodeModel node = personService.geTreeNodeModel(cid); //查詢cid下的全部子節點(SELECT * FROM tb_tree t WHERE t.pid=?) MiddleOrgEntity entity = new MiddleOrgEntity(); entity.setTableName(TableConstants.EWX_MIDDEL_ORG); entity.setParent_org_code(org_code); List<MiddleOrgEntity> middleOrgEntityList = commonService.selectListByExample(entity); //List childTreeNodeModels = personService.queryTreeNodeModel(cid); //遍歷子節點 for(MiddleOrgEntity child : middleOrgEntityList) { TreeNodeModel n = recursiveTree(child.getOrg_code()); //遞歸 treeNodeModel.getNodes().add(n); } return treeNodeModel; }