<div >
<span th:if ="${session.isEmpty()}">
<!-- <a href="login"><i ></i> Login</a></span> -->
<a href="login"><i ></i> Login</a></span>
<span th:if = "${!session.isEmpty()}">
<span th:text="${session.uid}"></span>
<a href="logout"><i ></i>Logout</a></span>
</div>
spring boot/thymleaf is their another method when that is in session its showing directly logout is their any other method to slove my problem
CodePudding user response:
<div >
<span th:if ="${session.isEmpty()}">
<!-- <a href="login"><i ></i> Login</a></span> -->
<a href="login"><i ></i> Login</a></span>
<span th:if = "${!session.isEmpty()}">
<span th:text="${session.uid}"></span>
<a href="logout"><i ></i>Logout</a></span>
</div>
spring boot/thymleaf
is their another method when that is in session its showing directly logout is their any other method to slove my problem
CodePudding user response:
In your html tag add namespace,
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
In pom.xml, ensure you have the following dependency
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
and then in html, you can use tag sec:authorize
, like:
<div sec:authorize="isAnonymous()">
<a href="login"><i ></i>Login</a>
</div>
<div sec:authorize="isAuthenticated()">
<a href="logout"><i ></i>Logout</a>
</div>