Spring----学习(14)----前置通知 && 后置通知

前置通知:在方法执行之前执行的通知

前置通知使用 @Before 注解, 并将切入点表达式的值作为注解值.

•后置通知是在连接点完成之后执行的, 即连接点返回结果或者抛出异常的时候, 注意此时还无法获取目标方法的执行结果

@Aspect
@Component
public class Log {
    //前置通知:在目标方法之前执行
	@Before("execution(int com.lishenhuan.aop.impl.ArithmeticCalculator.*(int, int))")
	public void before(JoinPoint joinPoint) {
		//获取目标方法名称
		String mathodName = joinPoint.getSignature().getName();
		//获取目标方法参数
		List<Object> args = Arrays.asList(joinPoint.getArgs());
		System.out.println("The method " + mathodName + " begin with " +args);
 	}
   @After("execution(int com.lishenhuan.aop.impl.ArithmeticCalculator.*(int, int))")
		public void after(JoinPoint joinPoint) {
			String mathodName = joinPoint.getSignature().getName();
			List<Object> args = Arrays.asList(joinPoint.getArgs());
			Sy
}

猜你喜欢

转载自blog.csdn.net/lsh15846393847/article/details/88976472
今日推荐