package com.dhtech.core.manager;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
* @className com.cetcthz.core.util
* @date 2019/05/01
* @Version 1.0
* @describe: 上下文工具
*/
public class ContextHolderUtils {
/**
* SpringMvc下获取request
*
* @return
*/
public static final HttpServletRequest getRequest() {
ServletRequestAttributes requestAttributes = ServletRequestAttributes.class.
cast(RequestContextHolder.getRequestAttributes());
if (StringUtils.isEmpty(requestAttributes)) {
return null;
}
HttpServletRequest contextRequest = requestAttributes.getRequest();
return contextRequest;
}
/**
* SpringMvc下获取session
*
* @return
*/
public static final HttpSession getSession() {
HttpSession session = getRequest().getSession();
return session;
}
}
SpringMVC 获取上下文工具类
最新推荐文章于 2022-12-02 11:26:23 发布