【问题标题】:Thymeleaf Shiro dialect custom expressionThymeleaf Shiro 方言自定义表达
【发布时间】:2015-12-18 23:33:39
【问题描述】:

我正在遍历一个列表并像这样为每个div 设置一个shiro:hasPermission 属性

<div th:each="element : ${elements}" shiro:hasPermission="${element.permission}">
    <span th:text="${element.name}"></span>
</div>

其中${element.permission} 是权限字符串。

即使用户有权限,也不会呈现 div。我试过像这样使用th:attr:

<div th:each="element : ${elements}" th:attr="shiro:hasPermission=${element.permission}">
    <span th:text="${element.name}"></span>
</div> 

还是不行。我认为shiro:hasPermission="${element.permission}" 的用法不正确。我该如何解决这个问题?

我正在使用 Spring MVC + Thymeleaf + Thymeleaf Shiro dialect。

【问题讨论】:

  • 首先检查权限是否正确显示,例如使用 th:text="${element.permision} 将它们 sysout 或在浏览器中显示它们。它们可能没有以 shiro 理解的方式格式化:也许你需要格式化它:shiro:hasPermission="' user:'+${element.permission}" 所以它看起来像 "user:create"
  • @Blejzer 我已经使用 th:text="${element.permission}" 检查了表达式。这很好用。我需要知道 shiro:hasPermission 是否可以正确评估表达式 ${element.permission}

标签: spring-mvc thymeleaf shiro


【解决方案1】:

我是thymeleaf-extras-shiro 库的作者。

版本 1.2.2-SNAPSHOT 支持表达式。

【讨论】:

  • @tbk 我正在使用 thymeleaf-extras-shiro 1.0.0 版。有什么解决办法,不升级到1.2.2版本?
  • @faizi 恐怕这是不可能的。尝试升级到 1.2.2 - 没有重大变化。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-09
  • 2017-02-18
  • 1970-01-01
  • 2015-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多