![](https://csdnimg.cn/release/download_crawler_static/86366109/bg4.jpg)
1.2.2 ThreadLocal 工具类
public class UserThreadLocal {
/**
* 如何存取多个数据?? Map 集合
* ThreadLocal<Map<k,v>>
*/
private static ThreadLocal<User> thread = new
ThreadLocal<>();
//新增数据
public static void set(User user) {
thread.set(user);
}
//获取数据
public static User get() {
return thread.get();
}
//使用 threadlocal 切记关闭 防止内存泄漏
public static void remove() {
thread.remove();
}
}
1.2.3 编辑拦截器
@Component //将拦截器交给 spring 容器管理
public class UserInterceptor implements HandlerInterceptor{
@Autowired
private JedisCluster jedisCluster;
/**
* 在 spring4 版本中要求必须重写 3 个方法,不管是否需要