优化获取用户信息
This commit is contained in:
parent
52267de141
commit
01bd257e6c
|
@ -18,7 +18,7 @@ public class SecurityUser {
|
|||
try {
|
||||
user = (UserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
} catch (Exception e) {
|
||||
return new UserDetail();
|
||||
return null;
|
||||
}
|
||||
|
||||
return user;
|
||||
|
@ -28,7 +28,12 @@ public class SecurityUser {
|
|||
* 获取用户ID
|
||||
*/
|
||||
public static Long getUserId() {
|
||||
return getUser().getId();
|
||||
UserDetail user = getUser();
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return user.getId();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user