@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;
}
}
在springAOP里面获取request和response对象
最新推荐文章于 2024-08-05 15:01:49 发布