springboot Thymeleaf 获取已登陆用户信息

一、使用场景

在个人中心等界面显示已登陆的用户信息

二、参考文献

https://blog.csdn.net/gisboygogogo/article/details/78758815

https://my.oschina.net/Cubicluo/blog/831111

三、使用方法

3.1 pom

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

3.2 html界面

注意点1:

<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

使用:span里不用填内容 

<div>账户:<span sec:authentication="name"></span></div>
<div><span sec:authentication="principal.authorities"></span></div>

猜你喜欢

转载自my.oschina.net/Cubicluo/blog/1803236