赞
踩
环绕通知所用的架包和前置通知所用的架包一样,并且在bean中添加aop
通知实现接口MethodInterceptor
并且实现其中的public Object invoke(MethodInvocation invocation)方法
环绕通知的功能非常的强大
它可以实现前置通知,后置通知,和异常通知
前置通知和后置通知在try中实现,
使用result = invocation.proceed();来控制目标方法的执行
写在invocation.proceed();前面的通知,为前置通知
写在invocation.proceed();后面的通知,为后置通知
环绕通知
- package all;
-
- import org.aopalliance.intercept.MethodInterceptor;
- import org.aopalliance.intercept.MethodInvocation;
-
- public class aopAround implements MethodInterceptor{
- Object result = null;
- @Override
- public Object invoke(MethodInvocation invocation) throws Throwable {
- try {
- System.out.println("用环绕通知实现前置通知");
- System.out.println("目标对象"+invocation.getThis()+"调用的方法名"+invocation.getMethod().getName()+"方法的参数"+invocation.getArguments().length);
- // invocation.proceed();之前的代码就是前置通知
- res
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。