NutzCN Logo
问答 Shiro标签使用性能
发布于 2975天前 作者 qq_a1b6f073 5708 次浏览 复制 上一个帖子 下一个帖子
标签:
    资源管理里面根据权限来是否显示create按钮
<c:forEach items="${resourceList}" var="resource">
            <tr data-tt-id='${resource.id}' <c:if test="${not resource.rootNode}">data-tt-parent-id='${resource.parentId}'</c:if>>
                <td>${resource.name}</td>
                <td>${resource.type.info}</td>
                <td>${resource.url}</td>
                <td>${resource.permission}</td>
                <td>
                	<c:if test="${resource.available==true}">
                	<!-- <i class="fa fa-check"></i> -->显示
                	</c:if>
                	<c:if test="${resource.available==false}">
                	<!-- <i class="fa fa-close"></i> -->隐藏
                	</c:if>
                </td>
                <td><i class="${resource.faicon}"></i></td>
                <td>${resource.sort}</td>
                <td>
                    <shiro:hasPermission name="resource:create">
                        <c:if test="${resource.type ne 'button'}">
                        <a href="${base}/resource/${resource.id}/appendChild" class="btn btn-green" data-toggle="dialog" data-id="node_add_child" data-mask="true">添加子节点</a>
                        </c:if>
                    </shiro:hasPermission>

                    <shiro:hasPermission name="resource:update">
                    	<a href="${base}/resource/${resource.id}/update" class="btn btn-green" data-toggle="dialog" data-id="node_edit" data-mask="true">修改</a>
                    </shiro:hasPermission>
                    <c:if test="${not resource.rootNode}">
                    <shiro:hasPermission name="resource:delete">
                        <a href="${base}/resource/${resource.id}/delete" class="btn btn-red" data-toggle="doajax" data-type="get"  data-confirm-msg="确定要删除吗?">删</a>
                    </shiro:hasPermission>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
这样的遍历会非常慢,如何改进?原因是<shiro:hasPermission>引起的
11 回复

在循环之前判断权限,然后设置为变量,在循环内直接判断变量是值,如何

另外一个系统的开发者也是这个意思,后台组装了操作组的HTML

获取返回某一页面的按扭组
public List<ResFormMap> findByRes() {
        // 资源ID
        String id = getPara("id");
        // 获取request
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        // 通过工具类获取当前登录的bean
        UserFormMap userFormMap = (UserFormMap) Common.findUserSession(request);
        // user id
        int userId = userFormMap.getInt("id");
        ResFormMap resQueryForm = new ResFormMap();
        resQueryForm.put("parentId", id);
        resQueryForm.put("userId", userId);
        List<ResFormMap> rse = resourcesMapper.findRes(resQueryForm);
        // List<ResFormMap> rse = resourcesMapper.findByAttribute("parentId",
        // id, ResFormMap.class);
        for (ResFormMap resFormMap : rse) {
            Object o = resFormMap.get("description");
            if (o != null && !Common.isEmpty(o.toString())) {
                System.out.println(Common.stringtohtml(o.toString()));
                resFormMap.put("description", Common.stringtohtml(o.toString()));
            }
        }
        return rse;
    }

代码生成的结果为按钮组。

shiro 标签会有这个情况?

我自己定义了一个TLD来做这样一件事情,性能提升了一大截。求大神分析问题,持续改进

<c:if test="${zhangfn:hasPermission('resource:create')}">
                        <c:if test="${resource.type ne 'button'}">
                        <a href="${base}/resource/${resource.id}/appendChild" class="btn btn-green" data-toggle="dialog" data-id="node_add_child" data-mask="true">添加子节点</a>
                        </c:if>
                   	</c:if>

                    <c:if test="${zhangfn:hasPermission('resource:update')}">
                    	<a href="${base}/resource/${resource.id}/update" class="btn btn-green" data-toggle="dialog" data-id="node_edit" data-mask="true">修改</a>
                    </c:if>
                    <c:if test="${not resource.rootNode}">
                    <c:if test="${zhangfn:hasPermission('resource:delete')}">
                        <a href="${base}/resource/${resource.id}/delete" class="btn btn-red" data-toggle="doajax" data-type="get"  data-confirm-msg="确定要删除吗?">删</a>
                    </c:if>
                    </c:if>

@Rekoe 你可以试试,三十多条记录等待好长时间才能生成,爆炸。

@qq_a1b6f073
好 我试试

@qq_a1b6f073
刚试了试 没你说的那个问题
不过我用的是freemarker

<#list 0..30 as id>
  <@shiro.hasPermission name="resource:update">
	<li class="sep"></li><li class="normal" id="tb_20" onclick="HoverLi(1,20,${max});"><a href="frame/account/main" target="mainFrame">修改密码</a></li></@shiro.hasPermission>
</#list>

@Rekoe 这样就试不出来了,按我第一串代码来,JSTL,绝逼慢

@Rekoe freemarker本来就是优化页面渲染的

那估计是Jstl的问题了
不过 用你自己定义的标签的话 应该是最好的方式了

现在清楚了,shiro鉴权过程 都会去调用doGetAuthorizationInfo,如果设置了缓存,就不会去调用。

添加回复
请先登陆
回到顶部