优化JwtAuthenticationTokenFilter中的代码格式,修复部分空值处理逻辑

This commit is contained in:
syruan 2025-12-04 17:58:00 +08:00
parent 002907d98d
commit 6d5b2c2c65
1 changed files with 10 additions and 12 deletions

View File

@ -29,7 +29,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
@Autowired @Autowired
private JWTTokenService tokenService; private JWTTokenService tokenService;
@Value("${server.servlet.context-path}") @Value("${server.servlet.context-path:}")
public String path; public String path;
@Override @Override
@ -66,10 +66,8 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
Claims claims = JwtUtils.parseToken(jwtToken); Claims claims = JwtUtils.parseToken(jwtToken);
Integer userId = (Integer) claims.get(SecurityConstants.DETAILS_USER_ID); Integer userId = (Integer) claims.get(SecurityConstants.DETAILS_USER_ID);
String userName = (String) claims.get(SecurityConstants.DETAILS_USERNAME); String userName = (String) claims.get(SecurityConstants.DETAILS_USERNAME);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); System.err.println("异常401登录过期,token信息:" + jwtToken + ",地址" + uri);
ResultUtil.responseJson(response,ResultUtil.resultCode(401,"登录过期,请先登录")); ResultUtil.responseJson(response,ResultUtil.resultCode(401,"登录过期,请先登录"));
return; return;
} }