码迷,mamicode.com
首页 > Web开发 > 详细

Extjs,实现树形结构的总结

时间:2015-09-11 12:21:20      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

工作总结,用extjs、mybatis、springMVC实现树形显示班级

前台extjs实现树形代码如下:

       xtype : ‘combotree‘,
                    fieldLabel : ‘部门名称‘,
                    name : ‘deptId‘,
                    hiddenName : ‘deptId‘,
                    allowBlank : false,
                    width:235,
                    tree : new Ext.tree.TreePanel({
                                root : {
                                    expanded : true,
                                    id : ‘root‘
                                },
                                loader : new Ext.tree.TreeLoader({
                                            dataUrl : ‘dept/getDeptList‘
                                        }),
                                animate : true,
                                enableDD : true,
                                autoScroll : true,
                                height:400,
                                rootVisible : true
                            }),
                    listeners : {
                            select : function(combotree){
                                }
                            },
                            scope : this
                        }

后台,controller代码

/**
     * 查找带check的部门树
     *
     * @return
     */
    @RequestMapping(value="/getDeptList",method = RequestMethod.POST)
    @ResponseBody
    public List<Tree> getDeptList() {
        Criteria criteria = new Criteria();
        return gradeCourseService.getDeptList(criteria);
    }

dao层代码:

/**
     *
     * 方法描述 : 查询部门
     * @param criteria
     * @return list<Dept>集合
     */
    List<Dept>  getDeptList(Criteria criteria);

dao对应的mapper查询代码:

<!-- 查询学生部门 -->
    <select id="getDeptList" parameterType="Criteria" resultMap="depetMap">
        select
           a.dept_id deptId,
           a.dept_Name deptName,
           a.leaf leaf,
           b.dept_id deptPartpId,
           b.dept_name deptPartName
        from spauth.base_dept a,spauth.base_dept b
        where
            a.dept_type = ‘2‘
        and

            a.dept_id = b.dept_pid
        order
            by a.dept_id asc,
            b.dept_Id asc
    </select>
    <!-- 树叶模型 -->
    <resultMap type="cn.edu.hbcf.privilege.pojo.Dept" id="depetMap">
          <id property="deptId" column="deptId"/>
          <result property="deptName" column="deptName"/>
          <result property="leaf" column="leaf"/>
          <collection property="children" ofType="cn.edu.hbcf.privilege.pojo.Dept">
              <id property="deptId" column="deptPartpId"/>
              <result property="deptName" column="deptPartName"/>
          </collection>
      </resultMap>

service层代码:

/**
     * 获取部门下拉框列表
     * @return
     */
    List<Tree> getDeptList(Criteria criteria);

service层实现类代码:

public List<Tree> getDeptList(Criteria criteria) {
        List<Tree> resultTree = new ArrayList<Tree>();
        Tree treeNode = null;
        List<Dept> deptList = gradeCourseMapper.getDeptList(criteria);
        Dept dept = null;
        for(Iterator<Dept> it = deptList.iterator(); it.hasNext();){
            treeNode = new Tree();
            List<Tree> childTree =new ArrayList<Tree>();
            Tree childNode = null;
            Dept chilDept = null;
            dept = it.next();
            if(dept.getDeptName().equals("河北金融学院")){
                continue ;
            }
            treeNode.setText(dept.getDeptName());
            treeNode.setId(dept.getDeptId());
            for(Iterator<Dept> iter = dept.getChildren().iterator(); iter.hasNext();){
                childNode = new Tree();
                chilDept = iter.next();
                childNode.setText(chilDept.getDeptName());
                childNode.setId(chilDept.getDeptId());
                childNode.setLeaf(true);
                childTree.add(childNode);
                treeNode.setChildren(childTree);
            }
//            if(treeNode.getChildren().size()==0){//这是判断系节点是不是没有子节点。如果没有,就让系变为叶子节点。
//                treeNode.setLeaf(true);//变为叶子节点。
//            }
            resultTree.add(treeNode);
        }
        return resultTree;
    }

tree实体类代码:

package cn.edu.hbcf.common.vo;

import java.util.List;

/**
 * ext树菜单
 *
 * @author LiPenghui
 * @date 2012-02-24 19:06:00
 *
 */
public class Tree {

    private String id;
    private String name;
    private String text;
    private String iconCls;
    private boolean expanded;
    private boolean leaf;
    private String url;
    private List<Tree> children;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getIconCls() {
        return iconCls;
    }

    public void setIconCls(String iconCls) {
        this.iconCls = iconCls;
    }

    public boolean getExpanded() {
        return expanded;
    }

    public void setExpanded(boolean expanded) {
        this.expanded = expanded;
    }

    public boolean getLeaf() {
        return leaf;
    }

    public void setLeaf(boolean leaf) {
        this.leaf = leaf;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<Tree> getChildren() {
        return children;
    }

    public void setChildren(List<Tree> children) {
        this.children = children;
    }

}

dept实体类代码:

package cn.edu.hbcf.privilege.pojo;

import java.io.Serializable;
import java.util.List;
/**
 * 部门
 * @author 张周海
 */
public class Dept implements Serializable{
    
    /** 部门Id */
    private String deptId;
    /** 父部门 */
    private Dept parent;
    /** 部门名称 */
    private String deptName;
    /** 部门简介 */
    private String deptComment;
    /** 是否为根节点 0无1有*/
    private int leaf;
    
    /**
     * 显示顺序
     */
    private Integer displayIndex;
    
    /**
     * 是否为系所号
     */
    private Integer deptType;
    
    
    private List<Dept> children;
    
    
    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getDeptComment() {
        return deptComment;
    }

    public void setDeptComment(String deptComment) {
        this.deptComment = deptComment;
    }

    public int getLeaf() {
        return leaf;
    }

    public void setLeaf(int leaf) {
        this.leaf = leaf;
    }

    public void setParent(Dept parent) {
        this.parent = parent;
    }

    public Dept getParent() {
        return parent;
    }

    
    /**
     * @return the children
     */
    public List<Dept> getChildren() {
        return children;
    }

    /**
     * @param children the children to set
     */
    public void setChildren(List<Dept> children) {
        this.children = children;
    }

    /**
     * @return the displayIndex
     */
    public Integer getDisplayIndex() {
        return displayIndex;
    }

    /**
     * @param displayIndex the displayIndex to set
     */
    public void setDisplayIndex(Integer displayIndex) {
        this.displayIndex = displayIndex;
    }

    /**
     * @return the deptType
     */
    public Integer getDeptType() {
        return deptType;
    }

    /**
     * @param deptType the deptType to set
     */
    public void setDeptType(Integer deptType) {
        this.deptType = deptType;
    }

}

Extjs,实现树形结构的总结

标签:

原文地址:http://www.cnblogs.com/zrui-xyu/p/4800264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!