easyui 中 的同步树(1)

原创 2016年05月30日 16:50:54

1.先看一下easyUI,Tree组件要求的数据格式

[{
    "id":1,
    "text":"Folder1",
    "iconCls":"icon-save",
    "children":[{
        "text":"File1",
        "checked":true
    },{
        "text":"Books",
        "state":"open",
        "attributes":{
            "url":"/demo/book/abc",
            "price":100
        },
        "children":[{
            "text":"PhotoShop",
            "checked":true
        },{
            "id": 8,
            "text":"Sub Bookds",
            "state":"closed"
        }]
    }]
},{
    "text":"Languages",
    "state":"closed",
    "children":[{
        "text":"Java"
    },{
        "text":"C#"
    }]
}]

2.我以 学院,系,专业 的顺序在前台显示tree
下面是数据库表:
学院表:
这里写图片描述
系表:
这里写图片描述
专业表:
这里写图片描述

3.看下数据库中的实体

@Entity
@Table(name = "t_department", catalog = "xiaonei")
public class TDepartment implements java.io.Serializable {

    // Fields

    private Integer id;
    private String text;
    private Integer pid;
    private List<TMajor> children;

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

    public void setChildren(List<TMajor> children) {
        this.children = children;
    }
    // Constructors

    /** default constructor */
    public TDepartment() {
    }

    /** full constructor */
    public TDepartment(String text, Integer pid) {
        this.text = text;
        this.pid = pid;
    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

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

    @Column(name = "text", length = 36)
    public String getText() {
        return this.text;
    }

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

    @Column(name = "pid")
    public Integer getPid() {
        return this.pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

}

@Entity
@Table(name = "t_major", catalog = "xiaonei")
public class TMajor implements java.io.Serializable {

    // Fields

    private Integer id;
    private String text;
    private Integer pid;

    // Constructors

    /** default constructor */
    public TMajor() {
    }

    /** full constructor */
    public TMajor(String text, Integer pid) {
        this.text = text;
        this.pid = pid;
    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

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

    @Column(name = "text", length = 36)
    public String getText() {
        return this.text;
    }

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

    @Column(name = "pid")
    public Integer getPid() {
        return this.pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

}

@Entity
@Table(name = "t_academy", catalog = "xiaonei")
public class TAcademy implements java.io.Serializable {

    // Fields

    private Integer id;
    private String text;
    private List<TDepartment> children;


    // Constructors

    @Transient
    public List<TDepartment> getChildren() {
        return children;
    }

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

    /** default constructor */
    public TAcademy() {
    }

    /** full constructor */
    public TAcademy(String text) {
        this.text = text;
    }

    // Property accessors
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

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

    @Column(name = "text", length = 36)
    public String getText() {
        return this.text;
    }

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

}

4.看下后台组装easyui json格式(java),dao层和service层就不贴了

@RequestMapping("/getAllTree")
    public String getAllTree(HttpServletRequest request,HttpServletResponse response) throws Exception{
        List academyList = academyService.getAllAcademy();
        Iterator academyIt = academyList.iterator();
        /*
         * 这太复杂了,没法看啊---
         * */
        while(academyIt.hasNext()){

            TAcademy academy = (TAcademy) academyIt.next();

            List departmentList = departmentService.getAllDepartmentByAcademyId(academy.getId());

            Iterator departmentIt = departmentList.iterator();

            List addDepartmentList = new ArrayList();

            while(departmentIt.hasNext()){

                TDepartment department = (TDepartment) departmentIt.next();

                addDepartmentList.add(department);

                List majorList = majorService.getAllMajorByDepartmentId(department.getId());

                Iterator majorIt = majorList.iterator();

                List addMajorList = new ArrayList();

                while(majorIt.hasNext()){

                    TMajor major = (TMajor) majorIt.next();

                    addMajorList.add(major);
                }
                department.setChildren(addMajorList);
            }
            academy.setChildren(addDepartmentList);
        }
        JSONArray jn = JSONArray.fromObject(academyList);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(jn.toString());
        return null;
    }
}

5.看下前台

<body style="margin:15px;">
<script>
    $("#majorTree").tree({    
        url:"/xiaoneinew/tree/getAllTree"
    }); 
</script>
<ul id="majorTree"></ul>
</body>

6.效果图
这里写图片描述
这里写图片描述
7.注意

  • 在实体department和academy中,有关children字段我用了@Transient,就是不同数据库中同步,是hibernate中三种状态的一种。
  • 这是我第一次写easyui的tree,写的很不好,以后我会优化的。
版权声明:本文为博主原创文章,转载注明出处。 举报

相关文章推荐

easyUI同步树的详解

easyUI同步树的详解

利用easyUI的combobox打造自动提示组件

利用easyUI的combobox打造自动提示组件

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

easyui 中 的同步树(1)

1.先看一下easyUI,Tree组件要求的数据格式[{ "id":1, "text":"Folder1", "iconCls":"icon-save", "...

easyui 中 的同步树(2)

在上一篇文章中我写的那个同步树,我是使用了三张表。这次我是把三张表合成一张表,表名是t_academy,实体类名是TAcademy。1.先看下这个表结构 这个表只有三列,id不用解释,t...

easyui中最新版本的TreeGrid同步树形表格、同步加异步树形表格、树形表格分页且异步查看子节点

easyui中最新版本的TreeGrid同步树形表格、同步加异步树形表格、树形表格分页且异步查看子节点

Sql 中的where 1=1 问题

很多时候我们在学习Sql的时候我么总是会看到有些时候会用到一些看起来没有用的东西,比如说:select * from table where 1= 1; 但是为什么我们要用到那个where 1 = ...

jquery easyui 异步加载树

前端代码: $('#adinfotree').tree({ url: url, animate:true, onLoadSuccess: function(node, data){ var ...

03-树1 树的同构

题意给你两棵树,判断这两棵树是否同构。解题思路树同构说明树的大小完全相同,因此我们可以递归遍历树的时候,对于树A,B,我们访问A的左子树时,我们也可以同时访问B的右子树,同理访问A的右子树时,我们也可...

03-树1 树的同构

03-树1 树的同构   (25分) 给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)