导入标签库(第二个标签库springsecurity标签库在没导入时标签也起了作用):
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"><!-- Thymeleaf为我们提供的Spring Security的标签支持 -->
在网页中使用标签:
<span th:text="${session.SPRING_SECURITY_CONTEXT.authentication.principal.username}"></span>
或者
<span sec:authentication="name"></span>