Java easyui樹形表格TreeGrid的實現(xiàn)代碼
自己搞了一下午,終于用JAVA實現(xiàn)了數(shù)據(jù)網(wǎng)格。記錄一下實現(xiàn)的代碼。(PS:此處的easyui是1.5版本,樓主只貼了核心的代碼)
實現(xiàn)圖
JSP頁面
<head> //權(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){ //動態(tài)設置展開查詢的url $(this).treegrid('options').url = 'queryPrivilege.action?parentId='+row.id; } }); }) </script> </head> <body> <table id="tt" style="width:600px;height:400px"></table> </body>
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層接口代碼
JSONArray getMenu(int parentId);
ServiceImpl層代碼(實現(xiàn)service層)
@Override public JSONArray getMenu(int parentId) { // TODO Auto-generated method stub return (JSONArray)privilegeDao.getMenu(parentId); }
Dao層代碼
JSONArray getMenu(int parentId);
DaoImpl層代碼(實現(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ù)庫一覽
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java異常處理操作 Throwable、Exception、Error
這篇文章主要介紹了Java異常處理操作 Throwable、Exception、Error,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06Java?DelayQueue實現(xiàn)任務延時示例講解
DelayQueue是一個無界的BlockingQueue的實現(xiàn)類,用于放置實現(xiàn)了Delayed接口的對象,其中的對象只能在其到期時才能從隊列中取走。本文就來利用DelayQueue實現(xiàn)延時任務,感興趣的可以了解一下2022-09-09Spring中FactoryBean的高級用法實戰(zhàn)教程
FactoryBean是Spring框架的高級特性,允許自定義對象的創(chuàng)建過程,適用于復雜初始化邏輯,本文給大家介紹Spring中FactoryBean的高級用法實戰(zhàn),感興趣的朋友跟隨小編一起看看吧2024-09-09springboot maven 項目打包jar 最后名稱自定義的教程
這篇文章主要介紹了springboot maven 項目打包jar 最后名稱自定義的教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10java實現(xiàn)pdf文件截圖的方法【附PDFRenderer.jar下載】
這篇文章主要介紹了java實現(xiàn)pdf文件截圖的方法,結(jié)合實例形式分析了java基于PDFRenderer.jar進行pdf文件截圖的相關(guān)操作技巧,并附帶PDFRenderer.jar文件供讀者下載使用,需要的朋友可以參考下2018-01-01淺談HashMap、HashTable的key和value是否可為null
這篇文章主要介紹了淺談HashMap、HashTable的key和value是否可為null,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09