Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocalUser 对象内存储的类型冲突问题 #186

Open
colorful3 opened this issue Mar 5, 2021 · 0 comments
Open

LocalUser 对象内存储的类型冲突问题 #186

colorful3 opened this issue Mar 5, 2021 · 0 comments

Comments

@colorful3
Copy link
Member

colorful3 commented Mar 5, 2021

此问题属于 #185 的衍生问题。

LocalUser对象是线程安全的当前登录用户,除了 LinCMS 系统内的管理员用户(对应模型为UserDO)外,C端用户也需要同样设置到请求上下文中,甚至说除了用户需要设置到请求上下文中,其他数据也可能需要设置到请求上下文中。现在的 LocalUser 只能 set 和 get UserDO 类型的对象:

private static ThreadLocal<UserDO> local = new ThreadLocal<>();

这样 LocalUser 基本就不可复用了,如果 C 端用户同样需要设置线程安全的当前登录用户,就不得不重新封装一个类,但里面的代码除了所存储的类型基本都一样的,可以考虑把ThreadLocal 中的泛型UserDO类型改为Map<String, Object>,并将类重命名为 LinThreadLocal

    private static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();

这样无论开发者想要在ThreadLocalsetget什么类型的对象,就都可以通过该类来操作了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant