com.wangshanhai.power.utils.HttpContextUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shanhai-power-spring-boot-starter Show documentation
Show all versions of shanhai-power-spring-boot-starter Show documentation
山海Power - 基于SpringBoot的权限组件,极致精简,只为满足简单需要。
The newest version!
package com.wangshanhai.power.utils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* 上下文操作工具
* @author Shmily
*/
public class HttpContextUtils {
/**
* 获取当前用户请求
* @return
*/
public static HttpServletRequest getHttpServletRequest() {
RequestAttributes servletRequestAttributes = RequestContextHolder.getRequestAttributes();
if(servletRequestAttributes==null){
Logger.error("[getHttpServletRequest]-ServletRequestAttributes is null");
return null;
}
return ((ServletRequestAttributes)servletRequestAttributes).getRequest();
}
}