package com.urt.core.web; import javax.servlet.http.HttpSession; import com.urt.core.authority.entity.User; /** * 用户Session存储器,方便在Controller层以外获取用户 * @author happyqing * @date 2015-4-25 */ public class UserSession { private static final ThreadLocal<HttpSession> userSession = new ThreadLocal<HttpSession>(); public static void setUserSession(HttpSession session) { userSession.set(session); } public static HttpSession getUserSession() { return userSession.get(); } public static User getUser(){ return (User)userSession.get().getAttribute("user"); } public static void setAttribute(String key, Object value){ userSession.get().setAttribute(key, value); } public static Object getAttribute(String key){ return userSession.get().getAttribute(key); } }
相关推荐
NULL 博文链接:https://qixiaopeng.iteye.com/blog/551764
通向架构师的道路(第七天)之漫谈使用ThreadLocal改进你的层次的划分
feign调用session丢失解决方案, Hystrix传播ThreadLocal对象; 自定义熔断策略
javaee开发常见的模式有MVC模式,在C层中常常会再次分层,如:servlet(web层)、service(业务逻辑层)、dao(数据访问层),其中service和dao最容易混在一起,如转...所以,使用ThreadLocal可以解决这样的分层问题。
NULL 博文链接:https://bijian1013.iteye.com/blog/2380233
ThreadLocal入门教程。 讲解了线程安全和ThreadLocal的使用的基本知识。
ThreadLocal
ThreadLocal应用示例及理解,这个写了相关的示例,可以参考一下。
使用c3p0数据源,进行转账操作的小型简单练习;使用ThreadLocal控制事务中的connection唯一,实现mvc三层结构互不干扰。
理解ThreadLocal 理解ThreadLocal 理解ThreadLocal 理解ThreadLocal
虽然所有的线程都能访问到这个ThreadLocal实例,但是每个线程却只能访问到自己通过调用ThreadLocal的set()方法设置的值。即使是两个不同的线程在同一个ThreadLocal对象上设置了不同的值,他们仍然无法访问到对方的值...
NULL 博文链接:https://xuranpaoche.iteye.com/blog/1514071
NULL 博文链接:https://justsee.iteye.com/blog/791919
学习ThreadLocal,了解其中的原理,以及学习其中的优点!避免坑点!!
在我们日常 Web 开发中难免遇到需要把一个参数层层的传递到最内层,然后中间层根本不需要使用这个参数,或者是仅仅在特定的工具类中使用,这样我们完全没有必要在每一个方法里面都传递这样一个 通用的参数。...
Java中ThreadLocal的设计与使用.doc
session的丢失原因和解决方案,与viewstate和cookie 的区别
ThreadLocal源码分析和使用
ThreadLocal的几种误区ThreadLocal的几种误区ThreadLocal的几种误区