java树easyui_Java easyui树形表格TreeGrid的实现代码

自己搞了一下午,终于用JAVA实现了数据网格。记录一下实现的代码。(PS:此处的easyui是1.5版本,楼主只贴了核心的代码)

实现图

ff9962c477f41efe6bdea2b637e6a306.png

JSP页面

//权限列表

$( 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){

//动态设置展开查询的url

$(this).treegrid('options').url = 'queryPrivilege.action?parentId='+row.id;

}

});

})

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层代码(实现service层)

@Override

public JSONArray getMenu(int parentId) {

// TODO Auto-generated method stub

return (JSONArray)privilegeDao.getMenu(parentId);

}

Dao层代码

JSONArray getMenu(int parentId);

DaoImpl层代码(实现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)(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;

}

数据库一览

fe8c3c2e7e66e79c937b2f67f173316e.png

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持聚米学院。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值