ThreadLocal获取用户的信息
时间: 2023-08-19 17:09:59 浏览: 114
ThreadLocal是一种用于在多线程环境下存储线程局部变量的机制。在web项目中,可以使用ThreadLocal来获取用户的信息。具体的做法是,在拦截器中解析token获取到用户的信息User对象,然后将User对象存入ThreadLocal中。这样,在整个请求的生命周期内,我们就可以随时随地地获取到当前线程的User对象了。可以通过一个工具类如UserUtils.getCurrentUser()来使用ThreadLocal获取用户的信息。\[2\]\[3\]
#### 引用[.reference_title]
- *1* [使用ThreadLocal获取登录者的信息](https://blog.csdn.net/lhp1204/article/details/129495360)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v4^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [ThreadLocal获取用户信息](https://blog.csdn.net/qq_38737586/article/details/118661699)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v4^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文