posts - 431,  comments - 344,  trackbacks - 0

call(Signature)切入点的语法是:
pointcut <pointcut name>(<any values to be picked up>) : call(<optional  modifier> <return type> <class>.<method>(<parameter types>));

package com.eric.aspectj;

public aspect MyAspectj {
 pointcut callPointCut(MyClass myClass, int age, String name) : call(void com.eric.aspectj.MyClass.foo(int, String)) && target(myClass) && args(age, name);
 before(MyClass myClass, int age, String name) : callPointCut(myClass, age, name) {
  System.out.println("before...name : " + name + " age : " + age);
 }
 after(MyClass myClass, int age, String name) returning: callPointCut(myClass, age, name) {
  System.out.println("after...");
 }
}


package com.eric.aspectj;

public class MyClass {

 public void foo(int age, String name) {
  System.out.println("foo " + name + " age is " + age);
 }
 public static void main(String[] args) {
  MyClass object = new MyClass();
  object.foo(24, "Eric Chau");
 }
}

运行结果:
before...name : Eric Chau age : 24
foo Eric Chau age is 24
after...

posted on 2007-07-03 15:10 周锐 阅读(274) 评论(0)  编辑  收藏 所属分类: AspectJ

只有注册用户登录后才能发表评论。


网站导航: