1 package com.huoziqi.springboot.utils; 2 3 /** 4 * @version 1.0 5 * @Author 作者名 6 * @Date 2022/10/22 11:16 7 */ 8 9 import com.huoziqi.springboot.entity.User; 10 11 /** 12 * 保存用户信息 13 */ 14 public class UserThreadLocal { 15 16 private UserThreadLocal(){} 17 18 private static final ThreadLocal<User> LOCAL = new ThreadLocal<>(); 19 20 /** 21 * 存放用户信息 22 */ 23 public static void put(User user){ 24 LOCAL.set(user); 25 } 26 27 /** 28 * 获取用户信息 29 */ 30 public static User get(){ 31 return LOCAL.get(); 32 } 33 34 /** 35 * 移除掉用户信息,防止内存泄漏 36 */ 37 public static void remove(){ 38 LOCAL.remove(); 39 } 40 }
标签:简单,用户,UserThreadLocal,static,User,使用,LOCAL,public From: https://www.cnblogs.com/qijiangforever/p/17418875.html