1.导入依赖
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2. 在html页面中引入thymeleaf命名空间和security命名空间
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
3.示例
获取UsernamePasswordAuthenticationToken中所有getXXX的内容
登录账号:<span sec:authentication="name"></span><br/>
通过权限判断:
<button sec:authorize="hasAuthority('/insert')">新增</button>
通过角色判断:
<button sec:authorize="hasRole('abc')">新增</button>