Home > Java > javaTutorial > Detailed explanation of the sample code of Java easyui tree table TreeGrid (picture)

Detailed explanation of the sample code of Java easyui tree table TreeGrid (picture)

黄舟
Release: 2017-03-17 10:07:28
Original
2869 people have browsed it

This article mainly introduces the implementation code of Java easyui tree table TreeGrid in detail. It has certain reference value. Interested friends can refer to it.

I spent an afternoon and finally finally Implemented data grid using JAVA. Record the implemented code. (PS: The easyui here is version 1.5, the author only posted the core code)

Implementation diagram

Detailed explanation of the sample code of Java easyui tree table TreeGrid (picture)

JSP page


<head>
//权限列表
$( document ).ready(function(){
      var parentId = 0;
      $(&#39;#tt&#39;).treegrid({  
        url:&#39;queryPrivilege.action?parentId=&#39;+parentId,  
        idField:&#39;id&#39;,  
        treeField:&#39;RecordStatus&#39;,
        columns:[[  
          {title:&#39;id&#39;,field:&#39;id&#39;,width:180}, 
          {field:&#39;RecordStatus&#39;,title:&#39;RecordStatus&#39;,width:180} ,
          {field:&#39;PrivilegeOperation&#39;,title:&#39;PrivilegeOperation&#39;,width:180}  
        ]],
        onBeforeExpand:function(row){
          //动态设置展开查询的url
          $(this).treegrid(&#39;options&#39;).url = &#39;queryPrivilege.action?parentId=&#39;+row.id;  
        }
      }); 
    })
 </script>
 </head>
 <body>
<table id="tt" style="width:600px;height:400px"></table>
</body>
Copy after login

ACTION layer code

  //输出
    public PrintWriter out()throws IOException{
      HttpServletResponse response=ServletActionContext.getResponse(); 
      response.setContentType("text/html"); 
      response.setContentType("text/plain; charset=utf-8");
      PrintWriter out= response.getWriter();
      return out;
    }  
  public String queryPrivilege() throws IOException{
    returnpd="ok";
    JSONArray array =new JSONArray();    
    array = privilegeService.getMenu(parentId);
    String str=array.toString();
    out().print(str);
    out().flush();
    out().close();
    return returnpd;
  }
Copy after login

Service layerInterfacecode

JSONArray getMenu(int parentId);
Copy after login
Copy after login

ServiceImpl layer code (implementing the service layer)

@Override
  public JSONArray getMenu(int parentId) {
    // TODO Auto-generated method stub
    return (JSONArray)privilegeDao.getMenu(parentId);
  }
Copy after login

Dao layer code

JSONArray getMenu(int parentId);
Copy after login
Copy after login

DaoImpl layer code (implementing Dao layer)

  @Override
  public JSONArray getMenu(int parentId) {
    // TODO Auto-generated method stub
    String hql="";
    JSONArray array=new JSONArray();
    hql="FROM Privilege p WHERE p.parentID = "+parentId;
    for(Privilege privilege:(List<Privilege>)(getSession().createQuery(hql).list())){
      JSONObject jo=new JSONObject();
      jo.put("id", privilege.getId());
      jo.put("RecordStatus", privilege.getRecordStatus());
      jo.put("parendId",privilege.getParentID());
       if(privilege.getParentID()==0){
          jo.put("state","closed");        
        }
        else{
          jo.put("state","open");
          System.out.println(parentId);
        }
      array.add(jo);
    }
    return array;
  }
Copy after login

Database overview

Detailed explanation of the sample code of Java easyui tree table TreeGrid (picture)

The above is the detailed content of Detailed explanation of the sample code of Java easyui tree table TreeGrid (picture). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template