springmvc中 request 和response

        //通知的签名
//        Signature signature = joinPoint.getSignature();
//        if ("login".equals(signature.getName())) {
//            return joinPoint.proceed();
//        }else{
//            //获取RequestAttributes
//            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
//            //从获取RequestAttributes中获取HttpServletRequest的信息
//            HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
//            String token = request.getHeader("token");
//            //如果要获取Session信息的话,可以这样写:
//            String idStr = fastJsonRedisTemplate.opsForValue().get(BopsConstant.USER_LOGIN_PREFIX + token);
//            if (StringUtils.isNotBlank(idStr)) {
//                return joinPoint.proceed();
//            }
//            List<String> list = new ArrayList();
//            list.add(ResultStatusEnum.INVALID_TOKEN + "");
//            list.add("登录已过期");
//            return list;

//        }


public class RequestHolder {
    public static HttpServletRequest getRequest(){
        HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return req;
    }

    public static HttpServletResponse getResponse(){
        HttpServletResponse resp = ((ServletWebRequest)RequestContextHolder.getRequestAttributes()).getResponse();
        return resp;
    }
}

阅读更多

没有更多推荐了,返回首页