MAP集合key value 应用
<div class="accordion" fillSpace="sidebar">
<c:forEach var="setting" items="${settings}">
<div class="accordionHeader">
<h2>
<span>Folder</span>${setting.key.resourcename}
</h2>
</div>
<div class="accordionContent">
<c:forEach var="sr" items="${setting.value}">
<ul class="tree">
<li><a href="${ctx}/${sr.key.url}" target="navTab" rel="${sr.key.rel}" <c:if test="${sr.key.isExist==1}">checked="true" </c:if>>${sr.key.resourcename}</a>
<c:forEach var="thr" items="${sr.value}">
<ul>
<li><a href="${ctx}/${thr.url}" target="navTab" rel="${thr.rel}" <c:if test="${r.isExist==1}">checked="true" </c:if>>${thr.resourcename}</a></li>
</ul>
</c:forEach>
</li>
</ul>
</c:forEach>
</div>
</c:forEach>
</div>
--------------------------------------------------------------------------------------------------------------------------------------------------------
业务逻辑层
/**
* 根据User查找拥有的菜单权限
* return Map<一级菜单,Map<二级菜单,三级菜单>>
* */
public Map<SysResource, Map<SysResource, List<SysResource>>> findUserSysResource(int id){
List<SysResource> settings = sysResourceMapper.findByUserId(id);
Map<SysResource, Map<SysResource, List<SysResource>>> result = new LinkedHashMap<SysResource, Map<SysResource, List<SysResource>>>();
//将结果转化为map
if(settings != null && settings.size() > 0){
Map<SysResource, List<SysResource>> seconds = new LinkedHashMap<SysResource, List<SysResource>>();
for(SysResource pfs : settings){
seconds = new LinkedHashMap<SysResource, List<SysResource>>();
if(pfs.getType().intValue()==1){
//类型为主菜单时新增主菜单及下级菜单
Map<String,Object> param = new HashMap();
param.put("id", id);
param.put("pid", pfs.getId());
int a = pfs.getId();
List<SysResource> tmp = sysResourceMapper.findChildSysResourceByUserId(param);
if(tmp.size()>0){
pfs.setIsExist(1);
}
for(SysResource sr:tmp){
param = new HashMap();
param.put("id", id);
param.put("pid", sr.getId());
List<SysResource> ptmp = sysResourceMapper.findChildSysResourceByUserId(param);
seconds.put(sr, ptmp);
if(ptmp.size()>0){
sr.setIsExist(1);
}
}
result.put(pfs, seconds);
}
}
}
return result;
}