我正在与 jhipster 合作。我需要创建一个新表来审核数据库更改,并将其与 Jhipster 生成的默认 jhi_persistenet_audit_event 表链接。如何从 jhi_persistenet_audit_event 表中获取当前记录的用户记录,以将该 ID 链接到我的新表?
最佳答案
Solution 1: Principal principal
@RequestMapping(value = {"/", ""})
public String start(Principal principal, Model model) {
String currentUser = principal.getName();
return currentUser;
}
<小时/>
Solution 2: Authentication authentication
@RequestMapping(value = {"/", ""})
public String currentUserName(Authentication authentication) {
return authentication.getName();
}
<小时/>
Solution 3: SecurityContextHolder
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
String username = ((UserDetails)principal).getUsername();
} else {
String username = principal.toString();
}
关于mysql - 获取 jhi_persistenet_audit_event 表的当前记录用户详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55320534/