递归算法解析成树形结构

/**
     * 递归算法解析成树形结构
     *
     * @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;
    }

 

posted on 2016-04-25 20:55  诡计的不老歌  阅读(1266)  评论(0编辑  收藏  举报