优化获取用户信息

This commit is contained in:
阿沐 2023-06-16 11:26:52 +08:00
parent 52267de141
commit 01bd257e6c

View File

@ -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();
}
}