Thymeleaf + Spring Secucity - > #authentication无法在链接位置与另一个位置结合使用

时间:2015-01-21 12:19:48

标签: java spring spring-security thymeleaf

我正在尝试在链接(${#authentication.systemUser.tenant.url})中使用符号@{}。当我尝试在文本位置(${})执行相同操作时,此用法对我有用。

我的代码:

文字位置:

<strong th:text="${#authentication.systemUser.name}" />

这是在屏幕上打印 Maciel Bombonato

链接位置:

<a th:href="@{/${#authentication.systemUser.tenant.url}/user}" > 
    <i class="fa fa-tachometer"></i>
    <span th:text="#{user.dashboard}" />
</a>

这会创建指向http://localhost:8080/${#authentication.systemUser.tenant.url}/user的链接,但我正在等待http://localhost:8080/apolo/user

写完这个问题后,我做了最后一次测试和工作。

我的解决方案如下。

首先创建一个div来使用th:with创建一些变量并涉及链接,并在此处:链接将被组成。

    <div th:with="dashboard=${'/'} + ${#authentication.systemUser.tenant.url} + ${'/user'},
          profile=${'/'} + ${#authentication.systemUser.tenant.url} + ${'/user/view/'} + ${#authentication.systemUser.id}
" >
        <a th:href="@{${dashboard}}" >
            <i class="fa fa-tachometer"></i>
            <span th:text="#{user.dashboard}" />
        </a>

    </div>

在这种情况下,我在DIV中声明了所有变量,然后在链接中使用它。

现在生成的链接是:http://localhost:8080/apolo/user

1 个答案:

答案 0 :(得分:2)

我认为这个问题与使用a的值构建href url有关 变量表达式。

您可以使用管道|执行文字替换(doc)。

<a th:href="@{|/${#authentication.systemUser.tenant.url}/user|}" > 
    <i class="fa fa-tachometer"></i>
    <span th:text="#{user.dashboard}" />
</a>
相关问题