我正在开发一个电子商务网站,并且仅当 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 中获得自动完成功能。
尝试用这种方式:
<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