Class DinoContextThreadLocalImpl
java.lang.Object
cn.dinodev.spring.commons.context.DinoContextThreadLocalImpl
- All Implemented Interfaces:
DinoContext
DinoContext 的ThreadLocal版本的实现- Author:
- Cody Lu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription获取当前租户voidcurrentTenant(Tenant tenant) 设置当前租户信息<K extends Serializable>
User<K> 获取当前登录的用户<K extends Serializable>
voidcurrentUser(User<K> user) 设置当前用户static org.springframework.context.ApplicationContextstatic Tenant获取当前线程的租户信息。static <T extends User<?>>
T获取当前线程的用户信息。static voidremove()清除当前线程的所有上下文信息。static voidsetApplicationContext(org.springframework.context.ApplicationContext context) static voidsetCurrentTenant(Tenant tenant) 设置当前线程的租户信息。static <T extends User<?>>
voidsetCurrentUser(T user) 设置当前线程的用户信息。
-
Constructor Details
-
DinoContextThreadLocalImpl
public DinoContextThreadLocalImpl()
-
-
Method Details
-
getCurrentTenant
获取当前线程的租户信息。从ThreadLocal存储中获取当前线程关联的租户对象。
- Returns:
- 当前租户信息,可能为null
-
setCurrentTenant
设置当前线程的租户信息。将租户信息存储到ThreadLocal中,如果传入null则移除租户信息。
- Parameters:
tenant- 要设置的租户信息,null表示清除
-
remove
public static void remove()清除当前线程的所有上下文信息。移除当前线程中存储的所有资源信息,包括租户和用户信息。
-
getCurrentUser
获取当前线程的用户信息。从ThreadLocal存储中获取当前线程关联的用户对象。
- Type Parameters:
T- 用户类型- Returns:
- 当前用户信息,可能为null
-
setCurrentUser
设置当前线程的用户信息。将用户信息存储到ThreadLocal中,如果传入null则移除用户信息。
- Type Parameters:
T- 用户类型- Parameters:
user- 要设置的用户信息,null表示清除
-
setApplicationContext
public static void setApplicationContext(org.springframework.context.ApplicationContext context) -
getApplicationContext
public static org.springframework.context.ApplicationContext getApplicationContext() -
currentUser
Description copied from interface:DinoContext获取当前登录的用户- Specified by:
currentUserin interfaceDinoContext- Type Parameters:
K- 用户ID类型参数- Returns:
- 当前登录用户信息,如果未登录则返回null
-
currentTenant
Description copied from interface:DinoContext获取当前租户- Specified by:
currentTenantin interfaceDinoContext- Returns:
-
currentUser
Description copied from interface:DinoContext设置当前用户- Specified by:
currentUserin interfaceDinoContext- Type Parameters:
K-- Parameters:
user-
-
currentTenant
Description copied from interface:DinoContext设置当前租户信息- Specified by:
currentTenantin interfaceDinoContext- Parameters:
tenant-
-