public static HttpServletRequest getRequest() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if (servletRequestAttributes == null) {
throw (new NotWebContextException("非 web 上下文无法获取 HttpServletRequest")).setCode(20101);
} else {
return servletRequestAttributes.getRequest();
}
}
public static HttpServletResponse getResponse() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if (servletRequestAttributes == null) {
throw (new NotWebContextException("非 web 上下文无法获取 HttpServletResponse")).setCode(20101);
} else {
return servletRequestAttributes.getResponse();
}
}
静态方法获取HttpServletRequest以及HttpServletResponse
最新推荐文章于 2024-04-03 09:03:07 发布