如何访问thymeleaf中的url`

问题描述 投票:0回答:1

我正在开发一个电子商务网站,并且仅当 url 与 /auth/login 不匹配时,我才想有条件地在布局中显示 div。

    <div sec:authorize="isAnonymous()" th:if="${!/auth/login}">
        <a th:href="@{/auth/login}">Login</a>
        <a th:href="@{/auth/register}">Register</a>
    </div>

我阅读了文档,但我所能找到的只是 params 对象的信息。我还在 google 上看到了一些关于 #httpservlet 对象的内容,但是我确实认为这是贬值的,因为我没有在 intellij 中获得自动完成功能。

spring-boot spring-mvc spring-thymeleaf
1个回答
0
投票

尝试用这种方式:

<div sec:authorize="isAnonymous()" th:if="${#httpServletRequest.requestURI != '/auth/login'}">
    <a th:href="@{/auth/login}">Login</a>
    <a th:href="@{/auth/register}">Register</a>
</div>.

有关该实现的有用链接:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appendix-a-expression-basic-objects

© www.soinside.com 2019 - 2024. All rights reserved.