/**
* 獲取當前用戶
*
* @return 取不到返回 new User()
*/
public static LoginUser getLoginUser() {
try {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal != null) {
LoginUser user =(LoginUser)principal;
if (user != null) {
return user;
}
return new LoginUser();
}
} catch (Exception ex) {
}
// 如果沒有登錄,則返回實例化空的User對象。
return new LoginUser();
}