java的Aop

切面表达式

复制代码
            1)execution(* *(..))
            //表示匹配所有方法

            2)execution(public * com.controller.UserController.*(..))
            //表示匹配com.controller.UserController类或接口中所有的公有方法

            3)execution(* com.controller..*.*(..))
            //表示匹配com.savage.server包及其子包下的所有方法,4大权限修饰符
            //public,protected,private,default

            4)execution(* get*(..))
            //表示以 get开始的方法

            5)execution(* com.controller.*.*(..))
            //controller包下的任何的方法
java 复制代码
 AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext("com.org.zhurenjin.mySpring.aop");
        OperateAddDelchengyi implOperate = (OperateAddDelchengyi)annotationConfigApplicationContext.getBean("implOperate");
        System.out.println(implOperate);
        implOperate.add(2,6);
        implOperate.del(2,6);
        implOperate.chengyi(2,6);
java 复制代码
package com.org.zhurenjin.mySpring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
@EnableAspectJAutoProxy
public class AopAspect {
    

    @Before("execution(public int com.org.zhurenjin.mySpring.aop.ImplOperate.*(..))")
    public void before(JoinPoint joinPoint){
        String name = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        System.out.println(name+"方法的参数是"+ Arrays.toString(args));
    }


    @AfterReturning(value = "execution(public int com.org.zhurenjin.mySpring.aop.ImplOperate.*(..))",returning = "result")
    public void afterReturn(JoinPoint joinPoint,Object result){
        String name = joinPoint.getSignature().getName();
        System.out.println(name+"方法的返回的数据是"+ result);
    }
}
相关推荐
sharemylove10 分钟前
Java 异常与常用类 学习笔记
java·开发语言·经验分享·笔记·学习
小灰灰搞电子14 分钟前
C 语言基础:动态内存管理详解
c语言·开发语言
打工仔折腾 AI21 分钟前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
Amumu121381 小时前
TypeScript学习: 进阶知识
开发语言·学习·typescript
炸薯条!2 小时前
Python基础学习:文件操作详解(打开、读取、写入与路径)
java·服务器·python
Dreams_l2 小时前
基于SpringBoot实现的抽奖系统(四)
java·spring boot·后端
这个昵称不容易2 小时前
SpringBoot 网上订餐系统设计与实现:80 个 Java 文件、91 个接口,附真实运行截图
java·springboot·毕设
Helix2502 小时前
JDK异常处理最佳实践:受检异常、非受检异常、try-catch-finally与全局异常处理完整指南
java·开发语言·jdk·异常处理·全局异常·自定义异常·try-catch
时间的情敌3 小时前
Three.js 后处理辉光 Bloom、告警发光效果、管线流光、着色器流动管线(ShaderMaterial)
开发语言·javascript·three.js·着色器
Evand J4 小时前
【CIR系列2】UWB视距(LOS)与非视距(NLOS)信道冲激响应(CIR)建模与对比,MATLAB
开发语言·matlab·信号处理·nlos·cir