首页 > 编程知识 正文

什么是aop,aop的作用是什么,aop的使用场景

时间:2023-05-05 18:20:05 阅读:20668 作者:2968

面向切片的编程的简称

AOP定义:

AOP由预编译方式和运行时动态代理实现,是一种在不修改源代码的情况下,在程序中动态统一添加功能的技术,简称AOP。 是spring框架的重要内容之一,是面向对象编程(OOP )的派生模型。

APP角色:

利用AOP隔离业务逻辑的各个部分,降低业务逻辑的耦合性,提高程序的可复用性和开发效率。

主要用于对同一对象层次的公共行为建模

常见的通知

先行通知方法执行前调用对应注释@Before后续通知方法执行后调用对应注释@After回复通知方法返回后调用对应注释@AfterReturning异常通知方法异常调用对应注释@ after therh

import java.util.Arrays; importorg.AspectJ.lang.join point; importorg.AspectJ.lang.annotation.after; importorg.AspectJ.lang.annotation.after returning; importorg.AspectJ.lang.annotation.after throwing; importorg.AspectJ.lang.annotation.aspect; importorg.AspectJ.lang.annotation.before; importorg.AspectJ.lang.annotation.pointcut; @ aspectpublicclasslogaspects {//通用切口表达式//1、类引用//2和其他切面引用@pointcut('execution ) }类名称的全路径:例如包名称切口表达式(指定以何种方式进行切口) before(pointcut () publicvoidlogstart (joint join point ) ) { object [ ] args=join point.getargs system.out.println (' join point.get signature ) ).getName ) '将运行。 @Before:参数列表为{'Arrays.aslist(Args ) ' } ); } @ after (com.atguigu.AOP.log aspects.pointcut ) (publicvoidlogend ) joinpointjoinpoint ) system.out.priint。 @After '; }//JoinPoint始终是参数表中的第一位@ after returning (value=' pointcut )、returning='result ) publicvoidlogreturn (joinpoturn ) 。 @AfterReturning:执行结果: {' result '}; } @ after throwing (value=' pointcut (,throwing='exception ' ) publicvoidlogexception ) joinpoint,exception。 异常信息: {' exception '}; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。