说明
(1)JDK版本:1.8
(2)Spring Boot 2.0.6
(3)Spring Security 5.0.9
(4)Spring Data JPA 2.0.11.RELEASE
(5)hibernate5.2.17.Final
(6)MySQLDriver 5.1.47
(7)MySQL 8.0.12
一、获取当前用户信息
1.1 从页面上显示当前登陆的用户名
<h1>欢迎使用Spring Security!
当前登录账号:<label th:text="${name}"></label>
,通过标签设置: <label sec:authentication="name"></label>
</h1>
1.2 在程序中获得当前登陆用户对应的对象
@GetMapping({"","/","/index"})
public String index(Model model) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if("anonymousU