Spring AOP demo

初七5977 40 0 RAR 2019-04-06 06:04:12

基于注解与 XML 配置文件两种形式的 AOP demo。 基于 xml 配置文件的 aop 管理 ```xml ``` Java 类 ```java public class LoggingAspect { public void beforeMethod(JoinPoint joinPoint) { System.out.println("在目标方法执行之前执行" + ", 要拦截的方法是:" + joinPoint.getSignature()); } public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = joinPoint.getArgs(); // 判断目标方法参数,满足条件修改参数值 if(" See You Again".equals(args[0])) { args[0] = " See You Again ..."; } // 在目标方法执行之前执行,相当于前置通知 System.out.println("这是一个前置通知"); // 执行目标方法 Object result = joinPoint.proceed(args); // 在目标方法执行之后之后,相当于后置通知 System.out.println("这是一个后置通知"); return result; } } ublic void com.jas.aop.bean.PersonImpl.sayHello())"/> ``` Java 类 ```java public class LoggingAspect { public void beforeMethod(JoinPoint joinPoint) { System.out.println("在目标方法执行之前执行" + ", 要拦截的方法是:" + joinPoint.getSignature()); } public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = joinPoint.getArgs(); // 判断目标方法参数,满足条件修改参数值 if(" See You Again".equals(args[0])) { args[0] = " See You Again ..."; } // 在目标方法执行之前执行,相当于前置通知 System.out.println("这是一个前置通知"); // 执行目标方法 Object result = joinPoint.proceed(args); // 在目标方法执行之后之后,相当于后置通知 System.out.println("这是一个后置通知"); return result; } }

用户评论
请输入评论内容
评分:
暂无评论