Skip to content

主题端有什么方法可以在Thymeleaf的th:if中校验是否已登录吗 #7052

Closed Answered by guqing
mjsoftking asked this question in Q&A
Discussion options

You must be logged in to vote

@mjsoftking 有以下两种方式可以在主题端判断是否登录

  1. 使用 ${#authentication.name} 取值如果得到 anonymousUser 表示未登录,否则会得到已登录用户的用户名
<p th:if="${#authentication.name != 'anonymousUser'}">
  已登录
</p>
  1. 使用 Spring Security Dialect
<div sec:authorize="isAuthenticated()">
  已登录
</div>

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by guqing
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants