Spring aop execution() 是最常見的切點函數


execution() 是最常見的切點函數,語法形式為

excution(<修飾符模式> ? <返回類型模式> <方法名模式>(<參數模式>) <異常模式>?) 
實例代碼
 1 package com.aop.learn.aspectj;
 2 
 3 import org.aspectj.lang.annotation.Aspect;
 4 import org.aspectj.lang.annotation.Before;
 5 import org.springframework.stereotype.Component;
 6 
 7 /**
 8  * @author songshuiyang
 9  * @title: execution() 實例
10  * @description:
11  * @date 2017/11/18
12  */
13 @Aspect
14 @Component
15 public class ExecutionAspect {
16 
17     /**
18      * 匹配所有目標類的public方法
19      */
20     @Before("execution(public * *(..))")
21     public void beforeAspect(){
22 
23     }
24     /**
25      * 匹配所有以To為后綴的方法
26      */
27     @Before("execution(* *To(..))")
28     public void beforeAspect1(){
29 
30     }
31     /**
32      * 匹配Waiter接口中的所有方法
33      */
34     @Before("execution(* com.aop.learn.service.Writer.*(..))")
35     public void beforeAspect2(){
36 
37     }
38     /**
39      * 匹配Waiter接口中及其實現類的方法
40      */
41     @Before("execution(* com.aop.learn.service.Writer+.*(..))")
42     public void beforeAspect3(){
43 
44     }
45     /**
46      * 匹配 com.aop.learn.service 包下所有類的所有方法
47      */
48     @Before("execution(* com.aop.learn.service.*(..))")
49     public void beforeAspect4(){
50 
51     }
52     /**
53      * 匹配 com.aop.learn.service 包,子孫包下所有類的所有方法
54      */
55     @Before("execution(* com.aop.learn.service..*(..))")
56     public void beforeAspect5(){
57 
58     }
59     /**
60      * 匹配 包名前綴為com的任何包下類名后綴為ive的方法,方法必須以Smart為前綴
61      */
62     @Before("execution(* com..*.*ive.Smart*(..))")
63     public void beforeAspect6(){
64 
65     }
66     /**
67      * 匹配 save(String name,int age) 函數
68      */
69     @Before("execution(* save(String,int))")
70     public void beforeAspect7(){
71 
72     }
73     /**
74      * 匹配 save(String name,*) 函數 第二個參數為任意類型
75      */
76     @Before("execution(* save(String,*))")
77     public void beforeAspect8(){
78 
79     }
80     /**
81      * 匹配 save(String name,..) 函數 除第一個參數固定外,接受后面有任意個入參且入參類型不限
82      */
83     @Before("execution(* save(String,..))")
84     public void beforeAspect9(){
85 
86     }
87     /**
88      * 匹配 save(String+) 函數  String+ 表示入參類型是String的子類
89      */
90     @Before("execution(* save(String+))")
91     public void beforeAspect10(){
92 
93     }
94 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM