@Data
public class BrokerInfo {
private static final ThreadLocal<UserBroker> userContext = new ThreadLocal<UserBroker>();
/**
* 存储用户信息
* @param userBroker
*/
public static void addUserContext(UserBroker userBroker) {
if (userBroker != null) {
userContext.set(userBroker);
}
}
/**
* 获取用户信息
* @return
*/
public static UserBroker getUserContext() {
return userContext.get();
}
/**
* 移除用户信息
*/
public static void removeUserContext() {
userContext.remove();
}
}
ThreadLocal保存当前用户
最新推荐文章于 2024-07-09 13:49:11 发布