参考:公共字段自动填充(ThreadLocal)

    1. //当前请求的用户id
    2. Long userId = Long.valueOf(decodedJWT.getClaim("id").asString());
    3. //当前线程上设置用户id,BaseContext是自己编写的类,注意一下
    4. BaseContext.setUserId(userId);
    5. log.info("token验证通过,threadLocal线程缓存用户id为:{}", userId);
    6. log.info("token验证通过,getUserId:{}", BaseContext.getUserId());
    7. //这个要放在最后,不然BaseContext的内容,后面读取不到
    8. filterChain.doFilter(request, response);
    9. return; //通过检测可以继续