AspectJ切點函式

2021-08-16 14:48:00 字數 1221 閱讀 8609

1. 方法切點函式

execution():根據匹配規則匹配

eg:前置增強@before(execution(public * *service(..)))

匹配所有以service結尾的方法

@annotation():根據相應的的註解匹配

eg:後置增強@afterreturning(「@annotation(com.sxd.annotation.tag)」)

只有方法註解了@tag才能匹配

2. 方法入參切點函式

args:根據輸入引數型別引數匹配

eg:環繞增強@around(com.sxd.domain.student)

輸入引數為student才能匹配(包含子類)

@args:根據輸入引數型別是否註解指定註解匹配

eg:丟擲增強@afterthrowing(com.sxd.annotation.respository)

比如輸入引數studentdao類上註解了@repository才能匹配(包含子類)

3. 目標類切點函式

within(): 根據匹配條件匹配

eg:fianl增強@after(within(com.sxd.service.*service))

service包下的以service結尾類所有的方法才能匹配,與execution類似,但只精確到類級別

@within():根據輸入引數註解型別匹配

eg:引介增強@declareparents(@within(com.sxd.annotation.tag))

匹配標註了@tag的類的子類和子孫類

target():根據型別匹配指定類來決定連線點是否匹配

eg:@before(target(com.sxd.service.baseservice))

匹配baseservice的實現類studentservice的所有方法(介面方法以及沒有在介面定義的方法)

@target():根據輸入引數註解型別匹配

eg:@before(@target(com.sxd.annotation.tag))

匹配只有標註了@tag的類(不包含其子類)

4. **類切點函式

this()

判斷**物件的類是否按型別匹配於指定類,如果匹配,則**物件的所有連線點匹配切點

切點函式詳解

一 annotation com.sias.a 匹配標註了 a的所有方法 二 execution 修飾符 返回值型別 方法名模式 引數模式 異常模式 通過方法簽名定義切點 execution public 匹配所有目標類的public方法 execution to 匹配目標類中所有方法名以to為字尾...

spring aop 切點函式基礎

詳細參考 表示匹配使用 annotation指定註解標註的方法將會被環繞 before value annotation com.ghq.cloud.anno.needtest 語法 execution 修飾符模式 返回值模式 方法名模式 引數模式 異常模式 例1 execution public ...

c primer 要點 函式

1.當用實參初始化形參時會忽略掉頂層const void fun const int i void fun int i 錯誤 重定義 底層const是可以過載的。2.在不同的作用域中無法過載函式名,而是隱藏。因為在c 語言中,名字查詢發生在型別檢查之前,所以內層作用域的會名字隱藏外層作用域,不分函式...