First, access to the current user information
1.1 displays the user name currently logged in from the page
<h1>欢迎使用Spring Security!
当前登录账号:<label th:text="${name}"></label>
,通过标签设置: <label sec:authentication="name"></label>
</h1>
1.2 subject is obtained corresponding to the user currently logged in the program
@GetMapping({"","/","/index"})
public String index(Model model) {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if("anonymousUser".equals(principal)) {
model.addAttribute("name","anonymous");
}else {
User user = (User)principal;
model.addAttribute("name",user.getUsername())