在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
想对作者说点什么? 我来说一句

BaseAction

2012年03月01日 1KB 下载

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

不良信息举报

在springAOP里面获取request和response对象

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭