package com.ayah.aop.aspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class TestAspect {
@Pointcut(value = "execution(* com.ayah.aop.service.*.*(..))")
public void executionAllMethod() {
}
@Around("executionAllMethod()")
public Object before(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs();
System.out.println("Around -> Before -> " + args[0] + " " + args[1]);
if (joinPoint.getSignature().getName().equals("test1")) {
args[0] = "*" + args[0];
args[1] = args[1] + "*";
} else if (joinPoint.getSignature().getName().equals("test2")) {
args[0] = (Integer) args[0] + 100;
args[1] = (Integer) args[1] + 100;
}
Object result = joinPoint.proceed(args);
System.out.println("Around -> After -> " + args[0] + " " + args[1]);
return result;
}
}