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

2018-09-12 13:30 更新

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

實現(xiàn)圖

JSP頁面

  1. <head>
  2. <script type="text/javascript">
  3. //權限列表
  4. $( document ).ready(function(){
  5. var parentId = 0;
  6. $('#tt').treegrid({
  7. url:'queryPrivilege.action?parentId='+parentId,
  8. idField:'id',
  9. treeField:'RecordStatus',
  10. columns:[[
  11. {title:'id',field:'id',width:180},
  12. {field:'RecordStatus',title:'RecordStatus',width:180} ,
  13. {field:'PrivilegeOperation',title:'PrivilegeOperation',width:180}
  14. ]],
  15. onBeforeExpand:function(row){
  16. //動態(tài)設置展開查詢的url
  17. $(this).treegrid('options').url = 'queryPrivilege.action?parentId='+row.id;
  18. }
  19. });
  20. })
  21. </script>
  22. </head>
  23. <body>
  24. <table id="tt" style="width:600px;height:400px"></table>
  25. </body>

java代碼

action層代碼

  1. //輸出
  2. public PrintWriter out()throws IOException{
  3. HttpServletResponse response=ServletActionContext.getResponse();
  4. response.setContentType("text/html");
  5. response.setContentType("text/plain; charset=utf-8");
  6. PrintWriter out= response.getWriter();
  7. return out;
  8. }
  9. public String queryPrivilege() throws IOException{
  10. returnpd="ok";
  11. JSONArray array =new JSONArray();
  12. array = privilegeService.getMenu(parentId);
  13. String str=array.toString();
  14. out().print(str);
  15. out().flush();
  16. out().close();
  17. return returnpd;
  18. }

Service層接口代碼

  1. public abstract JSONArray getMenu(int parentId);

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

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

Dao層代碼接口代碼

  1. public abstract JSONArray getMenu(int parentId);

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

  1. @Override
  2. public JSONArray getMenu(int parentId) {
  3. // TODO Auto-generated method stub
  4. String hql="";
  5. JSONArray array=new JSONArray();
  6. hql="FROM Privilege p WHERE p.parentID = "+parentId;
  7. for(Privilege privilege:(List<Privilege>)(getSession().createQuery(hql).list())){
  8. JSONObject jo=new JSONObject();
  9. jo.put("id", privilege.getId());
  10. jo.put("RecordStatus", privilege.getRecordStatus());
  11. jo.put("parendId",privilege.getParentID());
  12. if(privilege.getParentID()==0){
  13. jo.put("state","closed");
  14. }
  15. else{
  16. jo.put("state","open");
  17. System.out.println(parentId);
  18. }
  19. array.add(jo);
  20. }
  21. return array;
  22. }

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

轉載地址:http://www.jb51.net/article/108687.htm

以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號