30 lines
560 B
Java
30 lines
560 B
Java
package com.sky.common.context;
|
|
|
|
public class BaseContext {
|
|
public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();
|
|
|
|
/**
|
|
* 获取当前用户id
|
|
*
|
|
* @return 用户id
|
|
*/
|
|
public static Long getUserId() {
|
|
return threadLocal.get();
|
|
}
|
|
|
|
/**
|
|
* 设置用户id
|
|
* @param userId 用户id
|
|
*/
|
|
public static void setUserId(Long userId) {
|
|
threadLocal.set(userId);
|
|
}
|
|
|
|
/**
|
|
* 移出当前id
|
|
*/
|
|
public static void removeCurrentId() {
|
|
threadLocal.remove();
|
|
}
|
|
}
|