当前位置:   article > 正文

在springAOP里面获取request和response对象_aop获取response

aop获取response
@Component
@Aspect
public class WebControllerAop {
    @Pointcut("execution(* cn.sky.controller.*..*.*(..))")
    public void executeService() {
    }
    @Around(value="executeService()")//好的
//  @Around(value="executeService()&&(args(request,..) || args(..,request))")//好的
//  @Around(value="executeService()&&(args(..,request,response)||args(request,response,..))")//好的
    public Object doAroundAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Exception {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        Signature signature = proceedingJoinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature)signature;    
        Method targetMethod = methodSignature.getMethod();
        Method realMethod = proceedingJoinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), targetMethod.getParameterTypes()); 
        Object obj = proceedingJoinPoint.proceed();
        return obj;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/310008
推荐阅读
相关标签
  

闽ICP备14008679号