一、aspect的定义

   运行完HelloWorld以后,我们来看下aspect的基础语法:

1、定义一个切面: 关键字aspect。 这定义Java类的语法类似。

2、定义pointcut:  [修饰符(public,protected.....)] pointcut  poincut名字() :  表达式;

3、定义advice:   通知类型() : pointcut名字(){ .......逻辑}

   一个最基本的aspect,就是这样组成的。值得一提的是:aspectj支持很多类型的pointcut,最基本的就是method call pointcut(方法级别),而Spring的aop 仅支持method call pointcut。所以,在后面陆续的使用中,你将会发现aspectj的强大, 简直强大到有点过分。而至于advice,aspectj也一样,就是5种类型。

二、pointcut的主要类型

Methods and Constructors
call(Signature) every call to any method or constructor matching Signature at the call site(方法和构造函数的调用点)
execution(Signature) every execution of any method or constructor matching Signature (方法和构造函数的执行点)
Fields
get(Signature) every reference to any field matching Signature   (属性的读操作)
set(Signature) every assignment to any field matching Signature. The assigned value can be exposed with anargs pointcut (属性的写操作)
Exception Handlers
handler(TypePattern) every exception handler for any Throwable type in TypePattern. The exception value can be exposed with anargs pointcut(异常处理执行)
Advice
adviceexecution() every execution of any piece of advice(Advice执行)
Initialization
staticinitialization(TypePattern) every execution of a static initializer for any type in TypePattern  (类初始化)
initialization(Signature) every initialization of an object when the first constructor called in the type matchesSignature, encompassing the return from the super constructor call to the return of the first-called constructor (对象初始化)
preinitialization(Signature) every pre-initialization of an object when the first constructor called in the type matchesSignature, encompassing the entry of the first-called constructor to the call to the super constructor (对象预先初始化)
Lexical
within(TypePattern) every join point from code defined in a type in TypePattern  (捕获在指定类或者方面中的程序体中的所有连接点,包括内部类)
withincode(Signature) every join point from code defined in a method or constructor matching Signature (用于捕获在构造器或者方法中的所有连接点,包括在其中的本地类)
Instanceof checks and context exposure
this(Type or Id) every join point when the currently executing object is an instance of Type orId's type(所有Type or id 的实例的执行点,匹配所有的连接点,如方法调用,属性设置,当前的执行对象为Account,或者其子类。)
target(Type or Id) every join point when the target executing object is an instance of Type orId's type (配所有的连接点,目标对象为Type或Id)
args(Type or Id, ...) every join point when the arguments are instances of Types or the types of theIds (参数类型为Type)
Control Flow
cflow(Pointcut) every join point in the control flow of each join point P picked out byPointcut, including P itself  (捕获所有的连接点在指定的方法执行中,包括执行方法本身)
cflowbelow(Pointcut) every join point below the control flow of each join point P picked out byPointcut; does not include P itself (捕获所有的连接点在指定的方法执行中,除了执行方法本身)
Conditional
if(Expression) every join point when the boolean Expression is true
Combination (逻辑/结合操作)
! Pointcut every join point not picked out by Pointcut
Pointcut0 && Pointcut1 each join point picked out by both Pointcut0 and Pointcut1
Pointcut0 || Pointcut1 each join point picked out by either Pointcut0 or Pointcut1
( Pointcut ) each join point picked out by Pointcut

   

前面说过pointcut基于正则的语法,那么肯定也支持通配符,含义如下:

* 表示任何数量的字符,除了(.)
.. 表示任何数量的字符包括任何数量的(.)
+ 描述指定类型的任何子类或者子接口
同java一样,提供了一元和二元的条件表达操作符。
一元操作符:!
二元操作符:||和&&
优先权同java

跟我学aspectj之四 ----- pointcut基础语法相关推荐

  1. 前端学PHP之正则表达式基础语法

    前面的话 正则表达式是用于描述字符排列和匹配模式的一种语法规则.它主要用于字符串的模式分割.匹配.查找及替换操作.在PHP中,正则表达式一般是由正规字符和一些特殊字符(类似于通配符)联合构成的一个文本 ...

  2. Java是一门艺术讲究说学逗唱--Java基础语法

    Java是一门艺术,它讲究说学逗唱,一起领略java语法的美 Java 版本概述 在 Java 这门语言体系当中,最基础的部分就是 Java SE 部分,Java 的标准版本.它包括 Java 最基础 ...

  3. python简单学(一)基础语法

    最近在准备研究生阶段的学习,python是大二的时候学的,之后就一碰没碰,现在读起代码来是真的太吃力了,所以打算再过一遍python的相关知识,一起愉快的学习吧!(教程来源于菜鸟教程) 目录 标识符 ...

  4. python 取模_中年大叔学编程-Python的基础语法和运算符

    编程语言中都有语法,就是你按照语法规则来,程序才会顺利编译通过.今天我就来了解一下Python的基本语法. 保留关键字 保留关键字就是Python内置已经被使用了的关键字,我们不能用来自定义为变量名或 ...

  5. 【趣味学Python】Python基础语法讲解

    目录 编码 标识符 python保留字 注释 实例(Python 3.0+) 实例(Python 3.0+) 行与缩进

  6. 学完java基础语法之后用来练习的不依赖框架的小项目

    刚学完一门语言基础语法之后,一般都需要写一些小项目来检验我们的学习效果,将所学的基础语法串联起来,同时也熟悉一下用这门语言做项目的大概流程.但是此时学习的项目不能太复杂,因此此时才刚学完基础语法,太复 ...

  7. python基础语法总结-Python基础语法总结之逻辑运算

    Python里的逻辑运算有and.or 和 not,它们分别说明为与.或.非.虽然逻辑运算符在Python基础语法中是基础中的基础,但是对于零基础小白来讲,还是有一定难度的.本文就来为零基础小白好好讲 ...

  8. python基础语法手册_说一说python中的几个基础语法

    学一门语言,基础语法一定要扎实.就如盖房子一样,地基打得好,任凭风吹雨打,学习python也一样,学习很多东西都会花大量的时间来学习基础语法,对于毫无编程经验的新手而言,这样的无疑是很友好的,那么我们 ...

  9. go语言基础语法-for循环语句

    前言 循环语句,是基础语法中最重要的一部分,可以实现代码的反复执行. 一组被重复执行的语句称之为循环体,能否继续重复,决定循环的终止条件. 与其它主流编程语言不同的的是,Go语言中的循环语句只支持 f ...

最新文章

  1. HALCON标定倾斜安装镜头
  2. A.01.01—模块的输入—低端输入
  3. 关于Dictionary字典和List列表
  4. rocket mq 监听端口_MQ消息最终一致性解决方案
  5. osgearth_annotation示例
  6. Python RSA
  7. 硬盘空间分析工具 WizTree(转载)
  8. python ai 源码_2018年撩课学院-Python+人工智能/JavaEE/Web全栈/全学科下载_Python教程...
  9. 如何设置windows服务
  10. 微信公众号服务号怎么添加模板消息给所有粉丝群发
  11. 用 Python 切换输入法
  12. 路由器密码重置(不是适用于所有有些启动顺序数字不一样)
  13. Unity SKFramework框架(二十四)、Avatar Controller 第三人称控制
  14. Unity 场景练习02 仿风之旅人
  15. unreal无损音乐百度云_Roxette女主唱Marie Fredriksson - Den Standiga Resan 个人瑞典语专辑 [APE]...
  16. 做跨境电商需要哪些准备?
  17. MikTex中如何使用BibTeX添加参考文献
  18. JavaScript保留小数位数代码
  19. WDK学习笔记_基于区块链溯源系统的后端接口开发
  20. 太阳能板最大面积js

热门文章

  1. 转:pdf密码破解专题
  2. Vue国际区号组件开发(目前已经发布到npm)
  3. 名人名言——摘录自编程随想的博客
  4. iPhone开发中的技巧整理(二)
  5. vivo手机怎么恢复信息_vivo手机短信删除了怎么恢复-互盾安卓恢复大师
  6. 十款绝bi好用的硬盘数据恢复软件值得拥有简易恢复
  7. Android视频播放器架构接口的设计
  8. 【Axure视频教程】鼠标坐标函数Cursor
  9. python笔迹识别_关于机器视觉笔迹识别和Arduino控制机器人的设计
  10. maven仓库读取顺序