<%
var secondMenus=@shiro.getPrincipalProperty('secondMenus');
for(firstMenu in @shiro.getPrincipalProperty('firstMenus')){
%>
<%
var secondMenus=@shiro.getPrincipalProperty('secondMenus');
for(firstMenu in @shiro.getPrincipalProperty('firstMenus')){
%>
我现在用el表达式写的,firstMenus不显示出来 ,我把第二层作为和第三层作为menu ,我下面该怎么修改一下就能遍历出来了?
<div class="sidebar-collapse">
<ul class="nav" id="side-menu">
<c:forEach items="${shiro.getPrincipalProperty('firstMenus')}" var="firstMenus" >
<c:forEach items="${shiro.getPrincipalProperty('secondMenus')}" var="secondMenus" >
<li> <c:if test="${secondMenus.key ==firstMenus.path }">
<c:forEach items="${secondMenus.value}" var="secondMenu" >
<a href="#">
<i class="fa fa-circle-thin"></i>
<span class="nav-label">${secondMenu.name}</span>
<span class="fa arrow"></span>
</a>
</c:forEach>
</c:if>
<ul class="nav nav-second-level">
<c:if test="${secondMenus.key == secondMenu.path}">
<c:forEach items="${secondMenu.value}" var="thMenu" >
<li>
<a class="J_menuItem" href="${thMenu.href}" data-index="0">${thMenu.name}</a>
</li>
</c:forEach>
</c:if>
</ul>
</li>
</c:forEach>
</c:forEach>
</ul>
</div>
@wendal 下面这种语法,如果在jsp里面该怎么写啊?
for(firstMenu in @shiro.getPrincipalProperty('firstMenus')){
}
@wendal 为什么这么写 不行额?
<c:forEach items="${shiro.getPrincipalProperty('firstMenus')}" var="firstMenus" >
<c:forEach items="${shiro.getPrincipalProperty('secondMenus')}" var="secondMenus" >
<c:forEach items="${secondMenus[firstMenu.path]}" var="secondMenu" >
这么写${secondMenus[firstMenus.path]} 没有值
抛下面的异常信息
Caused by: javax.el.PropertyNotFoundException: Property '0001' not found on type java.util.HashMap$Node
那map实现不了我想要的,如果我想要nutzwk这样,secondMenus.get(secondMenu.path) ,通过path获取它下面的所有菜单,该怎么写啊?在jsp里面我这么写secondMenus.get(secondMenu.path) 不认。
<% for(secondMenu in @secondMenus.get(firstMenu.path)){ %>
<a href="<% if(!isEmpty(secondMenu.href)){ %><%if(@string.startWith(secondMenu.href,'/')){%>${base}${secondMenu.href!}<%}else{%>${secondMenu.href!}<%}%> <% }else{ %>javascript:;<% } %>" <%if(@string.startWith(secondMenu.target,'_')){%>target="${secondMenu.target!}"<%}else{%>${secondMenu.target!}<%}%>>
<% if(!isEmpty(@secondMenus.get(secondMenu.path))){ %><%}%>
<%if(lang=="zh_CN"){%>${secondMenu.name}<%}else{%>${secondMenu.aliasName}<%}%>
<% if(!isEmpty(@secondMenus.get(secondMenu.path))){ %>
<% for(thMenu in @secondMenus.get(secondMenu.path)){ %>
<a <% if(!isEmpty(thMenu.href)){ %>href="<%if(@string.startWith(thMenu.href,'/')){%>${base}${thMenu.href!}<%}else{%>${thMenu.href!}<%}%>" <% }else{ %>href="javascript:;"<% } %> <%if(@string.startWith(thMenu.target,'_')){%>target="${thMenu.target!}"<%}else{%>${thMenu.target!}<%}%>>
<%if(lang=="zh_CN"){%>${thMenu.name}<%}else{%>${thMenu.aliasName}<%}%>
<% }%>
<%}%>
<% } %>
<% } %>
<c:forEach items="${secondMenus.get(firstMenu.path)}" var="secondMenu" > 这么写的话抛下面的异常:
Caused by: javax.el.MethodNotFoundException: Method not found: class java.util.HashMap$Node.get(null)
这么写<c:forEach items="${secondMenus.value.[firstMenus.path]}" var="secondMenu" > 对吗,怎么还是抛异常呢
<c:forEach items="${shiro.getPrincipalProperty('firstMenus')}" var="firstMenus" >
<c:forEach items="${shiro.getPrincipalProperty('secondMenus')}" var="secondMenus" >
<li>
<c:forEach items="${secondMenus.value.[firstMenus.path]}" var="secondMenu" >
<a href="#">
<i class="fa fa-circle-thin"></i>
<span class="nav-label">${secondMenu.name}</span>
<span class="fa arrow"></span>
</a>
<ul class="nav nav-second-level">
</ul>
</li>
</c:forEach>
</c:forEach>
</c:forEach>
secondMenus是
Map<String, List<Menu>> secondMenus = new HashMap<>();
${secondMenus[firstMenus.value.path]} 抛下面的异常信息
Caused by: javax.el.PropertyNotFoundException: Property '0001' not found on type java.util.HashMap$Node
所以第二层foreach是多余的,删掉. 应该直接取
<c:forEach items="${shiro.getPrincipalProperty('secondMenus')}[firstMenus.value.path]}" var="secondMenu" >
@wendal 遍历出来了~~谢谢 谢谢!! 辛苦