转自:http://itlab.idcquan.com/Java/Spring/965349.html
spring aop expression 匹配多个条件 多个表达式
<aop:config>
<aop:pointcut expression="execution(* com.travelsky.ccboy.dao*.find*())|| execution(* com.travelsky.ccboy.dao*.query*())"
id="findCachePointcut" />
<aop:advisor advice-ref="jdbcInterceptor" pointcut-ref="findCachePointcut" />
</aop:config>
在多个表达式之间使用 ||,or表示 或,使用 &&,and表示 与,!表示 非。
上面的代码也可以改写成
<aop:config>
<aop:pointcut expression="(execution(* com.travelsky.ccboy.dao*.find*())) or(execution(* com.travelsky.ccboy.dao*.query*()))"
id="findCachePointcut" />
<aop:advisor advice-ref="jdbcInterceptor" pointcut-ref="findCachePointcut" />
</aop:config>
注意上面两中方法的不同点出了 将 || 改成了 or ,还有就是 每个execution都被()包含起来,建议为了区分不同的表达式 最好都是用()包装。
老外喜欢吧逻辑运算符用OR,and !写,国内一般用|| && !.

本文详细介绍了如何使用Spring AOP的expression语法匹配多个条件和多个表达式,包括使用||和or表示或,使用&&和and表示与,以及使用!表示非。同时提供了代码示例,并对比了不同表达方式的区别。
303

被折叠的 条评论
为什么被折叠?



