已集成security的情况
@Component
public class AuditorAwareImpl implements AuditorAware<String> {
@Override
public String getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || !authentication.isAuthenticated()) {
return "nobody";
}
return authentication.getPrincipal();
}
}
没有security的情况
@Component
public class AuditorAwareImpl implements AuditorAware<String> {
@Override
public String getCurrentAuditor() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
return request.getHeader("X-USER-ID");
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。