第一步:在left.jsp中
<script language="JavaScript" src="${pageContext.request.contextPath }/script/jquery-1.4.2.js"></script>
<script language="JavaScript" src="${pageContext.request.contextPath }/script/jquery-ztree-2.5.js"></script>
<script language="JavaScript" src="${pageContext.request.contextPath }/script/treeMenu.js"></script>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath }/css/menu.css" />
<link rel="stylesheet" href="${pageContext.request.contextPath }/css/zTreeStyle/zTreeStyle.css" type="text/css">
Left.jsp中使用<ul>
<TABLE border=0 width="20">
<TR>
<TD width=340px align=center valign=top>
<div class="zTreeDemoBackground">
<ul id="menuTree" class="tree" ></ul>
</div>
</TD>
</TR>
</TABLE>
第二步:在treeMenu.js中定義:
var menu = {
setting: {
isSimpleData: true,
treeNodeKey: "mid",
treeNodeParentKey: "pid",
showLine: true,
root: {
isRoot: true,
nodes: []
}
},
loadMenuTree:function(){
$.post("elecMenuAction_showMenu.do",{},function(data){
$("#menuTree").zTree(menu.setting, data);
});
}
};
$().ready(function(){
menu.loadMenuTree();
});
第三步:在Action中添加:
public String showMenu(){
//獲取Session中存放的權限字符串(格式:aa@ab@ac)
String popedom = (String) request.getSession().getAttribute("globle_popedom");
//1:查詢當前用戶所具有的功能權限,使用權限,查詢權限表,返回List<ElecPopedom>
List<ElecPopedom> list = elecRoleService.findPopedomListByUser(popedom);
//2:將list放置到棧頂,棧頂的對象轉換成json數組的形式
ValueStackUtils.setValueStack(list);
return "showMenu";
}
第四步:(hql語句嵌套查詢),Service類定義:
public List<ElecPopedom> findPopedomListByUser(String popedom) {
//hql語句和sql語句的嵌套查詢
String condition = " and o.mid IN('"+popedom.replace("@", "','")+"') AND isMenu = ?";
Object [] params = {true};
Map<String, String> orderby = new LinkedHashMap<String, String>();
orderby.put("o.mid", "asc");
List<ElecPopedom> list = elecPopedomDao.findCollectionByConditionNoPage(condition, params, orderby);
return list;
}
第五步:在struts.xml中添加:
<!-- 將集合壓入到棧頂,集合返回頁面的時候,轉換成json的形式 -->
<result name="showMenu" type="json"></result>