Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
isauthenticated()在spring中isanonymous()不起作用_Spring_Spring Boot_Spring Mvc_Spring Security - Fatal编程技术网

isauthenticated()在spring中isanonymous()不起作用

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>

我提供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> 
<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">