AspectJ简介
1.AspectJ簡介
?
2.切入點表達式【掌握】
execution()?
用于描述方法 【掌握】
| 語法:execution(修飾符? 返回值? 包.類.方法名(參數) throws異常) |
修飾符,一般省略
| public???????????????? | 公共方法 |
| *?? | 任意 |
返回值,不能省略
| void??????????????????? | 返回沒有值 |
| String???????????????? | 返回值字符串 |
| * ?????????????????????? | 任意 |
包,[省略]????????
| com.gyf.crm | 固定包 |
| com.gyf.crm.*.service? | crm包下面子包任意 (例如:com.gyf.crm.staff.service) |
| com.gyf.crm..?? | crm包下面的所有子包(含自己) |
| com.gyf.crm.*.service..?? | crm包下面任意子包,固定目錄service,service目錄任意包 |
類,[省略]
| UserServiceImpl????????????????????????? | 指定類 |
| *Impl | 以Impl結尾 |
| User*??? | 以User開頭 |
| *?????? | 任意 |
方法名,不能省略
| addUser??????????????????????????????????????? | 固定方法 |
| add*???????????? | 以add開頭 |
| *Do???????????? | 以Do結尾 |
| *?????????? | 任意 |
(參數)??????????
| ()?????? | 無參 |
| (int)?????? | 一個整型 |
| (int ,int)???? | 兩個 |
| (..)??????? | 參數任意 |
throws ,可省略,一般不寫。
?
案例1:
execution(* com.gyf.crm.*.service..*.*(..))
案例2:或
<aop:pointcut expression="execution(* com.gyf.crm.service.*.*(..)) ||?
execution(* com.gyf.*Do.*(..))" id="myPointCut"/>
within:
匹配包或子包中的方法(了解)
| within(com.gyf.aop..*) |
this:
匹配實現接口的代理對象中的方法(了解)
| this(com.gyf.aop.user.UserDAO) |
target:
匹配實現接口的目標對象中的方法(了解)
| target(com.gyf.aop.user.UserDAO) |
args:
匹配參數格式符合標準的方法(了解)
| args(int,int) |
bean(id)?
對指定的bean所有的方法(了解)
| bean('userServiceId') |
3.通知類型
?
總結
- 上一篇: 第一性原理·非线性成长·人生模式
- 下一篇: 路由器静态路由配置及连通性测试