isauthenticated()在spring中isanonymous()不起作用
我提供html和附件: 1.Myhtml文件:isauthenticated()在spring中isanonymous()不起作用,spring,spring-boot,spring-mvc,spring-security,Spring,Spring Boot,Spring Mvc,Spring Security,我提供html和附件: 1.Myhtml文件: <li><a href='#'>SHOOPING CART</a> <div sec:authorize="isAnonymous()"> <a class="btn btn-primary pull-right" th:href="@{/login}">My Account1</a> </div>
<li><a href='#'>SHOOPING CART</a>
<div sec:authorize="isAnonymous()">
<a class="btn btn-primary pull-right" th:href="@{/login}">My Account1</a>
</div>
<div sec:authorize="isAuthenticated()">
<a class="btn pull-right" th:href="@{/myProfile}">My Account</a>
<a class="btn pull-right" href="@{/logout}">Logout</a>
</div>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
2.我添加了以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>${thymeleaf-extras-springsecurity5.version}</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>${thymeleaf-extras-java8time.version}</version>
</dependency>
<dependency>
<groupId>io.github.jpenren</groupId>
<artifactId>thymeleaf-spring-data-dialect</artifactId>
<version>${thymeleaf-spring-data-dialect.version}</version>
</dependency>
<dependency
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
org.springframework.boot
弹簧启动装置
org.thymeleaf.extras
thymeleaf-extras-springsecurity5
${thymeleaf-extras-springsecurity5.version}
org.thymeleaf.extras
thymeleaf-extras-Java8时间
${thymeleaf-extras-java8time.version}
io.github.jpenren
thymeleaf spring数据方言
${thymeleaf spring数据方言.version}
我通过在html文件的开头添加以下代码得到了答案:
<li><a href='#'>SHOOPING CART</a>
<div sec:authorize="isAnonymous()">
<a class="btn btn-primary pull-right" th:href="@{/login}">My Account1</a>
</div>
<div sec:authorize="isAuthenticated()">
<a class="btn pull-right" th:href="@{/myProfile}">My Account</a>
<a class="btn pull-right" href="@{/logout}">Logout</a>
</div>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">