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. v$sysstat表解释
  2. android简单歌词,Yuan-LrcView
  3. Qt Creator制作动画
  4. php文件上传指定路径,php上传文件到指定文件夹
  5. mysql -b -e_MySQL 的B+树索引.
  6. 学信网:研究生云复试平台快速搭建上线
  7. QQ号终于可以当传家宝了!没车没房的,就留几个游戏账号给儿子吧?
  8. WSS3.0安装后,系统资源消耗这么大
  9. 单片机万年历阴阳历c语言,单片机 阴历阳历c算法 万年历
  10. fork函数与execve函数
  11. 华为USG6000V防火墙学习
  12. echarts 文本标签配置、label文字样式
  13. 阿里云对象存储OSS简介和使用
  14. php gd ttf,linux gd php TTF字体
  15. 【R实验.8】方差分析
  16. Linux安装GaussDB数据库图文,GaussDB 100 on Linux安装手册
  17. 虚树-树上动态规划的利器
  18. 当六月的雨,带了些许思念的时候,记忆的扉页,被忧伤一一翻阅
  19. A - Eddy‘s AC难题(C语言)
  20. ES自定义Analyzer扩展IK分词

热门文章

  1. Java学习笔记·Servlet parameter参数传递utf-8文字编码正常显示
  2. 微信小程序开发教程,大多数人都搞错的八个问题
  3. 看曾国藩家书有感(1)
  4. 动态规划---例题1.矩阵连乘问题
  5. H264和x264简单介绍
  6. linux编译lapack,blas、lapack、cblas在Ubuntu上的安装
  7. 系统分析师冲刺班练习题
  8. 烈火网 2011年3月15日 新闻、教程、资源归档
  9. python数据分析职位_python代写拉勾数据职位分析
  10. 35w奖金池,腾讯云TDSQL精英挑战赛等你来战。