首页 > 解决方案 > Thymeleaf 模板未显示用户名

问题描述

我的主页没有显示用户名,我正在使用 sec:authentication 标签

<li sec:authorize="isAuthenticated()"><a th:href="@{/logout}">Logout</a></li>
   </ul>
   </div>
   </nav>
   <br><br>
   <p>
			Welcome <span sec:authentication="principal.username">User</span>
   </p>

标签: spring-bootthymeleaf

解决方案


尝试这个:

<p>
  Welcome <span th:text="${#request.userPrincipal.name}">User</span>
</p>

推荐阅读