spring在非controlle项目中获取当前request

来源:互联网 发布:linux对文件内容排序 编辑:程序博客网 时间:2024/06/06 19:44

spring在非controlle项目中获取当前request

public static HttpServletRequest getCurrentRequest() throws IllegalStateException {        ServletRequestAttributes requestAttrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();        if (requestAttrs == null) {            throw new IllegalStateException("当前线程中不存在 Request 上下文");        }        return requestAttrs.getRequest();    }
阅读全文
0 0
原创粉丝点击