Html 如何使用isAuthenticated()和isAnonymous()使导航链接显示或不显示?

Html 如何使用isAuthenticated()和isAnonymous()使导航链接显示或不显示?,html,spring,bootstrap-4,thymeleaf,Html,Spring,Bootstrap 4,Thymeleaf,我只想展示两个元素中的一个。若用户登录,我需要显示MyProfile,否则显示MyAccount(匿名),但有两个方法总是返回true。我尝试了很多解决方案,但没有人能解决这个问题 header.xml pom.xml <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity4</artifa

我只想展示两个元素中的一个。若用户登录,我需要显示MyProfile,否则显示MyAccount(匿名),但有两个方法总是返回true。我尝试了很多解决方案,但没有人能解决这个问题

header.xml

pom.xml

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    <version>2.1.3.RELEASE</version>
</dependency>
<dependency>
 <groupId>org.thymeleaf.extras</groupId>
 <artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
并将其替换为:

xmlns:sec="http://www.w3.org/1999/xhtml"
我将编辑此帖子,并添加其他尝试来解决此问题

  • 编辑2:(解决方案) 我改变了pom.xml中dependecy的artifactId,一切正常

    org.thymeleaf.extras thymeleaf-extras-springsecurity5


更改了pom.xml中依赖关系的artifactId,一切正常:

pom.xml

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    <version>2.1.3.RELEASE</version>
</dependency>
<dependency>
 <groupId>org.thymeleaf.extras</groupId>
 <artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>

org.thymeleaf.extras
thymeleaf-extras-springsecurity5

您能描述一下您尝试过什么,以便有人可以修改您的尝试以使其生效吗?很抱歉,缺少信息,请看。
<dependency>
 <groupId>org.thymeleaf.extras</groupId>
 <artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>