import com.mmall.model.SysUser;
import javax.servlet.http.HttpServletRequest;
/**
* @Author: zhouheng
* @Created: with IntelliJ IDEA.
* @Description:
* @Date: 2018-07-17
* @Time: 14:56
*/
public class RequestHolder {private static final ThreadLocal USER_THREAD_LOCAL = new ThreadLocal();
private static final ThreadLocal REQUEST_THREAD_LOCAL = new ThreadLocal<>();
public static void add(SysUser sysUser) {
USER_THREAD_LOCAL.set(sysUser);
}public static void add(HttpServletRequest request) {
REQUEST_THREAD_LOCAL.set(request);
}public static SysUser getCurrentUser() {
return USER_THREAD_LOCAL.get();
}
public static HttpServletRequest getCurrentRequest() {
return REQUEST_THREAD_LOCAL.get();
}public static void remove() {
USER_THREAD_LOCAL.remove();
REQUEST_THREAD_LOCAL.remove();
}
}
【RequestHolder】
推荐阅读
- Eclipse中Spring的引入
- 在idea中 使tomcat中配置的虚拟路径生效
- javaSE|javaEE JDBC, dbutils插件, 事务
- Windows平台Redis的安装和配置
- javax.inject.jar(依赖注入非常方便的jar包)
- 在Win下搭建JSP开发环境
- windows下RocketMQ安装部署
- jstl判段对象是否为空
- BeanValidator