第一个*代表任何返回值
cn.com.dao.impl..*:代表你要拦截cn.com.dao.impl目录下的以及子目录下的所有类
.*(..):这个代表任意方法,就是说上面那些类的任意方法,()里面的点,代表任意参数
execution(* com.xyz.service.*.*(..))
com.xyz.service.*.*(..) 代表你要拦截com.xyz.service目录下的所有类
execution(* com.xyz.service.AccountService.*(..))
com.xyz.service.AccountService.*(..) 代表你要拦截AccountService接口的任意方法
execution(* com.xyz.service..JoinPointObjP2.*(..))
代表你要拦截com.xyz.service包和所有子包里的JoinPointObjP2类的任意方法的执行
execution(public * *(..))
代表你要拦截任意的public方法
execution(* set*(..))
代表你要拦截任何一个以“set”开始的方法
在多个表达式之间使用 ||,or表示 或,使用 &&,and表示 与,!表示 非.例如:
<aop:config> <aop:pointcut id="pointcut" expression="(execution(* com.ccboy.dao..*.find*(..))) or (execution(* com.ccboy.dao..*.query*(..)))"/> <aop:advisor advice-ref="jdbcInterceptor" pointcut-ref="pointcut" /> </aop:config>
请问execution(* cn.javass..*.*(..))这里,第一个星号和cn之间要空格,为什么呢?
答:语法规则,第一个* 代表任意返回值 如果不加空格 就无法和包名区分了
aop:pointcut 标签中"expression"的写法规则如下:
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)
ret-type-pattern,name-pattern(param-pattern)是必须的.
ret-type-pattern:标识方法的返回值,需要使用全路径的类名如java.lang.String,也可以为*表示任何返回值;
name-pattern:指定方法名,*代表所有,例如set*,代表以set开头的所有方法.
param-pattern:指定方法参数(声明的类型),(..)代表所有参数,(*)代表一个参数,(*,String)代表第一个参数为任何值,第二个为String类型.
参考:http://www.tuicool.com/articles/z6Jzqu2
http://www.cnblogs.com/qinyubin/p/4075466.html