1、切入點(diǎn)表達(dá)式:對(duì)指定的方法進(jìn)行攔截,并且生成代理表達(dá)式。
表達(dá)式語(yǔ)法:
execution([修飾符] 返回值類型 包名.類名.方法名(參數(shù)))
execution( public void com.test.service.impl.UsersService.add() )
2、表達(dá)式不同寫法
1.匹配指定方法
1 |
<aop:pointcut expression="execution( public void com.test.service.impl.UsersService.add())" id="pt"/>
|
---|---|
2.默認(rèn) public 可以省略
2 |
<aop:pointcut expression="execution( void com.test.service.impl.UsersService.add())" id=“pt”/>` |
---|---|
3.匹配任何返回值
3 |
<aop:pointcut expression="execution( * com.test.service.impl.UsersService.add())" id=“pt”/>` |
---|---|
4.參數(shù)列表可以使用 * , 表示可以是任何的數(shù)據(jù)類型,但必須有參數(shù)
4 |
<aop:pointcut expression="execution( * com.test.service.impl.UsersService.add(*))" id=“pt”/>` |
---|---|
5.參數(shù)列表可以使用 … 表示有無(wú)參數(shù)均可,有參數(shù)可以是任意類型
5 |
<aop:pointcut expression="execution( *com.test.service.impl.UsersService.add(..))" id=“pt”/>` |
---|---|
6.使用…來(lái)表示當(dāng)前包,及其子包
6 |
<aop:pointcut expression="execution( * com..UsersService.add(..))" id=“pt”/>` |
---|---|
7.類名可以使用*號(hào),表示任意類
7 |
<aop:pointcut expression="execution( * com..*.add(..))" id=“pt”/>` |
---|---|
8.類名也可以使用 * 加后綴,表示這個(gè)后綴的所有類
8 |
<aop:pointcut expression="execution( * com..*Service.add(..))" id=“pt”/>` |
---|---|
9.方法名可以使用*號(hào),表示任意方法
9 |
<aop:pointcut expression="execution( * com..*.*(..))" id=“pt”/>` |
---|---|
10.全通配方式execution( * ….* ( … ) )
10 |
<aop:pointcut expression="execution(public * *(..))" id="pt"/>
|
---|---|
11.攔截所有save開(kāi)頭的方法
11 |
<aop:pointcut expression="execution(* save*(..))" id="pt"/>
|
---|---|
12.多個(gè)表達(dá)式文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-691527.html
<aop:pointcut expression="execution(* 包名.類名.方法名()) || execution(* 包名.類名(不同的類).方法名())"` `id="pt"/>` `<aop:pointcut expression="execution(* ``包名.類名.方法名()) or execution(* 包名.類名(不同的類).方法名())"` `id="pt"/>
13.取非值文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-691527.html
13 |
<aop:pointcut expression="!execution(* 包名.類名.方法名())" id="pt"/> <aop:pointcut expression=" not execution(* 包名.類名.方法名())" id="pt"/>
|
---|---|
到了這里,關(guān)于javaee spring aop 切入點(diǎn)表達(dá)式的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!