在springAOP里面获取request和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;
    }
}
阅读更多
个人分类: java
想对作者说点什么? 我来说一句

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

关闭
关闭
关闭