Java easyui樹形表格TreeGrid的實(shí)現(xiàn)代碼

2018-09-12 13:30 更新

自己搞了一下午,終于用JAVA實(shí)現(xiàn)了數(shù)據(jù)網(wǎng)格。記錄一下實(shí)現(xiàn)的代碼。(PS:此處的easyui是1.5版本,樓主只貼了核心的代碼)

實(shí)現(xiàn)圖

JSP頁面

<head>
<script type="text/javascript">
//權(quán)限列表
$( document ).ready(function(){
      var parentId = 0;
      $('#tt').treegrid({  
        url:'queryPrivilege.action?parentId='+parentId,  
        idField:'id',  
        treeField:'RecordStatus',
        columns:[[  
          {title:'id',field:'id',width:180}, 
          {field:'RecordStatus',title:'RecordStatus',width:180} ,
          {field:'PrivilegeOperation',title:'PrivilegeOperation',width:180}  
        ]],
        onBeforeExpand:function(row){
          //動(dòng)態(tài)設(shè)置展開查詢的url
          $(this).treegrid('options').url = 'queryPrivilege.action?parentId='+row.id;  
        }
      }); 
    })
 </script>
 </head>
 <body>
<table id="tt" style="width:600px;height:400px"></table>
</body> 

java代碼

action層代碼

//輸出
  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;
}

Service層接口代碼

public abstract JSONArray getMenu(int parentId);

ServiceImpl層代碼(實(shí)現(xiàn)service層)

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

Dao層代碼接口代碼

public abstract JSONArray getMenu(int parentId);

DaoImpl層代碼(實(shí)現(xiàn)Dao層)

@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;
}

數(shù)據(jù)庫一覽

轉(zhuǎn)載地址:http://www.jb51.net/article/108687.htm

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)