まず、現在のユーザー情報へのアクセス
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("anonymousUser".equals(principal)) {
model.addAttribute("name","anonymous");
}else {
User user = (User)principal;
model.addAttribute("name",user.getUsername())