SpringBoot 随时随地获取Request

RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
                                      RequestContextHolder.getRequestAttributes();
        //从session里面获取对应的值
        String str = (String) requestAttributes.getAttribute("name",RequestAttributes.SCOPE_SESSION);

        HttpServletRequest request = ((ServletRequestAttributes)requestAttributes).getRequest();
        HttpServletResponse response = ((ServletRequestAttributes)requestAttributes).getResponse();

猜你喜欢

转载自blog.csdn.net/wenxingchen/article/details/85159958