package com.manage.util;


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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 关于作用域的操作
 * @Author: ljx
 * @Date: 2019/4/23 18:24
 * @Version 1.0
 */
public class ActionScopeUtils {

    public static HttpSession getSession(HttpServletRequest request){
        return request.getSession();
    }

    public static HttpServletRequest getRequest(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public static void setSessionAttribute(String key,Object value,int expireTime){
       getSession(getRequest()).setAttribute(key,value);
       getSession(getRequest()).setMaxInactiveInterval(expireTime);
    }

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