package com.bjpowernode.ba02;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import java.util.Date;
@Aspect
public class MyAspect {
/**
* 后置通知定义方法,方法是实现切面功能的
* 方法的定义要求
* 1. 公共方法public
* 2. 方法没有返回值
* 3. 方法名称自定义
* 4. 方法有参数,推荐是object 参数名自定义
*
*/
/**
* @AfterReturning 后置通知
* 属性1. value切入点位置
* 2. returning 自定义的变量,标识目标方法的返回值
* 自定义变量名必须和通知方法的形参一样
* 在方法定义的上面
* 特点:在目标方法之后执行的
* 能够获取到目标方法的返回值,可以根据这个返回值做不同的处理功能
*/
@AfterReturning(value = "execution(* doOther(..))",returning = "res")
public void doaspect(JoinPoint jp,String res){
if(res.equals("abcd")){
System.out.println("获得的返回值是"+res+"符合要求");
System.out.println(jp.getSignature().getName());
}
else{
System.out.println("获得的返回值不等于abcd,不符合要求");
}
}
}