spring aop参数传递

使用示例

HelloService

public interface HelloService {String hello();String hello(String name);String hello(String name, Integer age);
}

HelloServiceImpl

@Service
public class HelloServiceImpl implements HelloService {@Overridepublic String hello() {return "hello";}@Overridepublic String hello(String name) {return "hello " + name;}@Overridepublic String hello(String name, Integer age) {return "hello " + name + " " + age;}
}

CustomAspect

@Aspect
@Component
public class CustomAspect {@Pointcut("execution(* *.hello(..))")public void fun(){}@Pointcut("execution(* *.hello(String)) && args(name))")public void fun2(String name){}@Pointcut("execution(* *.hello(String,..)) && args(name))")public void fun3(String name){}@Pointcut("execution(* *.hello(String,Integer)) && args(name,age)")public void fun4(String name, Integer age){}@Before("fun()")public void before(JoinPoint joinPoint){System.out.print("before ==> ");process(joinPoint);}@Before("fun2(name)")public void before2(JoinPoint joinPoint,String name){System.out.print("before2 ==> " + name + " ==> ");process(joinPoint);}@Before("fun3(name)")public void after3(JoinPoint joinPoint,String name){System.out.print("after3 ==> "+ name + " ==> ");process(joinPoint);}@After("fun4(name,age)")public void after4(JoinPoint joinPoint, String name, Integer age){System.out.print("after4 ==> "+ name + " " +age + " ==> ");process(joinPoint);}public void process(JoinPoint joinPoint){MethodSignature signature =(MethodSignature) joinPoint.getSignature();Method method = signature.getMethod();System.out.println(method.getDeclaringClass().getName()+"."+method.getName()+":被调用");}
}

HelloController

@RestController
public class HelloController {@Resourceprivate HelloService helloService;@RequestMapping("/hello")public String hello(){return helloService.hello();}@RequestMapping("/hello2")public String hello2(){return helloService.hello("瓜田李下");}@RequestMapping("/hello3")public String hello3(){return helloService.hello("瓜田李下",20);}
}

使用示例

localhost:8080/hello,控制台输出:

before ==> com.example.demo.controller.HelloController.hello:被调用
before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用

localhost:8080/hello2,控制台输出:

after3 ==> 瓜田李下 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
before2 ==> 瓜田李下 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用

localhost:8080/hello3,控制台输出:

before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
after4 ==> 瓜田李下 20 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用

spring aop参数传递相关推荐

  1. Spring 学习——Spring AOP——AOP配置篇Advice(有参数传递)

    声明通知Advice 配置方式(以前置通知为例子) 方式一 <aop:config> <aop:aspect id="ikAspectAop" ref=" ...

  2. Spring学习总结(4)——Spring AOP教程

    2019独角兽企业重金招聘Python工程师标准>>> 一.概念 AOP(Aspect Oriented Programming):面向切面编程. 面向切面编程(也叫面向方面编程), ...

  3. Spring——AOP

    AOP AOP概述 AOP(Aspect-Oriented Programming,面向切面编程):是一种新的方法论,是对传统 OOP(Object-Oriented Programming,面向对象 ...

  4. 基于 Annotation 拦截的 Spring AOP 权限验证方法

    余 清, 软件工程师, IBM 简介: 使用 Annotation 可以非常方便的根据用户的不同角色,分配访问 Java 方法的权限.在 Java Web 开发中,使用这种方法,可以提高系统的松耦合度 ...

  5. Spring AOP详解(http://sishuok.com/forum/posts/list/281.html)

    三6.5  AspectJ切入点语法详解 6.5.1  Spring AOP支持的AspectJ切入点指示符 切入点指示符用来指示切入点表达式目的,,在Spring AOP中目前只有执行方法这一个连接 ...

  6. Spring AOP知识点简介

    文章目录 1.什么是AOP 1.1.AOP术语 1.2.AOP框架 2.动态代理 2.1.JDK动态代理 2.2.CGLIB动态代理 3.基于代理类的AOP实现 3.1.Spring的通知类型 3.2 ...

  7. spring aop组件_安全性中的Spring AOP –通过方面控制UI组件的创建

    spring aop组件 以下文章将显示在我参与的一个项目中,我们如何使用Spring的AOP来介绍一些与安全性相关的功能. 这样的概念是,为了使用户能够看到某些UI组件,他需要具有一定级别的安全特权 ...

  8. 安全性中的Spring AOP –通过方面控制UI组件的创建

    以下文章将显示在我参与的一个项目中,我们如何使用Spring的AOP来介绍一些与安全性相关的功能. 这样的概念是为了使用户能够看到一些UI组件,他需要具有一定级别的安全特权. 如果不满足该要求,则不会 ...

  9. Spring AOP看这个就够了

    AOP简介 AOP(Aspect-Oriented Programming,面向切面编程):是一种新的方法论,是对传统 OOP(Object-Oriented Programming,面向对象编程)的 ...

最新文章

  1. Nginx搭建静态网站
  2. 计算机基础知识自考真题,自考《计算机应用基础》基础试题
  3. 在 windows 7 和 MinGW 下编译 OpenOCD 过程
  4. 【插件】史上最强编辑器通用ctags插件OpenCTags使用指南v1.2--开发者必备
  5. SAP Spartacus footer区域的一些常见错误
  6. Linux日志系统分析:rsyslog、syslog和klog
  7. Django删除多对多表关系 :
  8. 2018-2019-2 20175105王鑫浩 实验二《Java面向对象程序设计》实验报告
  9. java 支付宝转账_Java 支付宝支付,退款,单笔转账到支付宝账户(支付宝订单退款)...
  10. Linux安装Gitlab
  11. Vim 的几个彩蛋。。
  12. 文献格式 ShareLaTeX and Overleaf
  13. python曲线图局部放大_python放大图片和画方格实现算法
  14. redis 菜鸟教程
  15. Vue 实现电子签名
  16. TortoiseCVS 安装遇到的一些问题
  17. C语言编译器开发之旅(二):解析器
  18. 什么是需求分析,如何进行需求分析?
  19. TIA博途中如何访问不同IP网段的PLC以及不同IP网段的PLC如何通信?
  20. python matplotlibmat 包mplot3d工具 三维视图透视取消

热门文章

  1. Move or commit them before merge
  2. 区分实时数据、离线数据、流式数据以及批量数据的区别
  3. 化学方程式系列( 试 制 品)(挑战密室)
  4. Online Anomalous Trajectory Detection with Deep Generative Sequence Modeling
  5. android 沉浸式状态栏 兼容低版本,Android 沉浸式状态栏适配方案
  6. 手把手教你前后端分离
  7. 【花雕】全国青少年机器人技术一级考试备考实操搭建手册10
  8. 怎么拍出最真是的自己?
  9. FS4068是USB充电器5V转16.8V四串升压充电芯片充电器IC
  10. CSDN收藏的资料位置,怎么切换编辑器,怎么转载博客