直接可使用的AOP(切面编程)

本文介绍了如何在Spring中使用AOP,包括导入相关依赖、创建注解以及具体的AOP实现步骤,帮助读者快速理解并应用AOP技术。
摘要由CSDN通过智能技术生成

导入依赖

<!-- aop切面 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>

创建注解

@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ViewRecords {
    long id() default  1L;

}

aop实现

@Slf4j
@Aspect
@Component
public class AnnotationAop {

    //定义切点,注解作为切入点
    @Pointcut("@annotation(com.qcby.teaching.msgmanage.annotation.ViewRecords)")
    public void viewRecordsPoinCut() {

    }
    /**
     * before 目标方法执行前执行,前置通知
     * after 目标方法执行后执行,后置通知
     * after returning 目标方法返回时执行 ,后置返回通知
     * after throwing 目标方法抛出异常时执行 异常通知
     * around 在目标函数执行中执行,可控制目标函数是否执行,环绕通知
     */

    @Before("viewRecordsPoinCut()")
    public void before(JoinPoint joinPoint) 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值