Class DinoContextThreadLocalImpl

java.lang.Object
cn.dinodev.spring.commons.context.DinoContextThreadLocalImpl
All Implemented Interfaces:
DinoContext

public class DinoContextThreadLocalImpl extends Object implements DinoContext
DinoContext 的ThreadLocal版本的实现
Author:
Cody Lu
  • Constructor Details

    • DinoContextThreadLocalImpl

      public DinoContextThreadLocalImpl()
  • Method Details

    • getCurrentTenant

      public static Tenant getCurrentTenant()
      获取当前线程的租户信息。

      从ThreadLocal存储中获取当前线程关联的租户对象。

      Returns:
      当前租户信息,可能为null
    • setCurrentTenant

      public static void setCurrentTenant(Tenant tenant)
      设置当前线程的租户信息。

      将租户信息存储到ThreadLocal中,如果传入null则移除租户信息。

      Parameters:
      tenant - 要设置的租户信息,null表示清除
    • remove

      public static void remove()
      清除当前线程的所有上下文信息。

      移除当前线程中存储的所有资源信息,包括租户和用户信息。

    • getCurrentUser

      public static <T extends User<?>> T getCurrentUser()
      获取当前线程的用户信息。

      从ThreadLocal存储中获取当前线程关联的用户对象。

      Type Parameters:
      T - 用户类型
      Returns:
      当前用户信息,可能为null
    • setCurrentUser

      public static <T extends User<?>> void setCurrentUser(T user)
      设置当前线程的用户信息。

      将用户信息存储到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

      public <K extends Serializable> User<K> currentUser()
      Description copied from interface: DinoContext
      获取当前登录的用户
      Specified by:
      currentUser in interface DinoContext
      Type Parameters:
      K - 用户ID类型参数
      Returns:
      当前登录用户信息,如果未登录则返回null
    • currentTenant

      public Tenant currentTenant()
      Description copied from interface: DinoContext
      获取当前租户
      Specified by:
      currentTenant in interface DinoContext
      Returns:
    • currentUser

      public <K extends Serializable> void currentUser(User<K> user)
      Description copied from interface: DinoContext
      设置当前用户
      Specified by:
      currentUser in interface DinoContext
      Type Parameters:
      K -
      Parameters:
      user -
    • currentTenant

      public void currentTenant(Tenant tenant)
      Description copied from interface: DinoContext
      设置当前租户信息
      Specified by:
      currentTenant in interface DinoContext
      Parameters:
      tenant -