1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| @Aspect public class MyAspect { @Pointcut("execution(* *.*(..))") public void myPointCut(){}
@Before("myPointCut()") public void before() { System.out.println("MyAspect.before"); }
@After("myPointCut()") public void after(){ System.out.println("MyAspect.after"); }
@Around("myPointCut()") public Object around(ProceedingJoinPoint pjp){
Object proceed = null; try { System.out.println("前"); System.out.println(pjp.getSignature().getName()); proceed = pjp.proceed(); System.out.println(pjp.getSignature().getName()); System.out.println("后"); } catch (Throwable throwable) { throwable.printStackTrace(); } return proceed; }
@AfterReturning(value = "myPointCut()",returning = "val") public void afterReturning(JoinPoint jp,Object val){ System.out.println("啦啦啦啦"+jp.getSignature().getName()); System.out.println("MyAspect.afterReturning"); } }
|