W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
自己搞了一下午,終于用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
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: