feat: BaseContext通过线程设置用户id
This commit is contained in:
parent
1c2b21ffeb
commit
25af5719ac
|
@ -0,0 +1,29 @@
|
|||
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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue