spring中获得sesion的工具类

开发中我们常常会用到session,但是传统的获取session的方法不是很灵活。。。

直接贴上源码:

package com.ibs.gbplatform.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class SessionUtils {

	public static Object getSessionAttribute(String key) {
		return ((ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes()).getRequest().getSession()
				.getAttribute(key);
	}

	public static void setSessionAttribute(String key, Object object) {
		((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
				.getRequest().getSession().setAttribute(key, object);
	}
}



你可能感兴趣的:(spring,session,源码,Java,Spring)