top.doudou.common.tool.utils.ServletUtils Maven / Gradle / Ivy
package top.doudou.common.tool.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;
import javax.servlet.http.HttpServletResponse;
/**
* 客户端工具类
*
* @author 傻男人<[email protected]>
*/
public class ServletUtils {
/**
* 获取request
*/
public static HttpServletRequest getRequest() {
return getRequestAttributes().getRequest();
}
/**
* 获取response
*/
public static HttpServletResponse getResponse() {
return getRequestAttributes().getResponse();
}
private static ServletRequestAttributes getRequestAttributes() {
RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
return (ServletRequestAttributes) attributes;
}
}