一、添加依赖:

<dependency>
   <groupId>org.thymeleaf.extras</groupId>
   <artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>



二、html头部添加:

<html 
   xmlns="http://www.w3.org/1999/xhtml" 
   xmlns:th="http://www.thymeleaf.org" 
   xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">

xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"   


三、使用:

1、获取用户名:

<span sec:authentication="name"></span>