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);
    }
}
相关推荐
万法若空9 小时前
【算法-查找】查找算法
java·数据结构·算法
殳翰9 小时前
下服务器端开发流程及相关工具介绍(C++)
开发语言·c++
落寞的星星10 小时前
这个对象就包含了已经转换好的DFA和各种词法分析器运转所需要的参数。下一步,我们就可以用ScannerInfo对象创建出Scanner对象,请看下面的代码:
开发语言·c#
nothing&nowhere10 小时前
用 Python 做问卷数据清洗:无效样本检测与处理实战
开发语言·python·数据清洗·数据处理·问卷星·问卷星脚本·刷问卷
2601_9615934210 小时前
Rust 开发环境配置繁琐?RustRover 开箱即用搞定编码调试
开发语言·后端·macos·rust
HZZD_HZZD11 小时前
DL/T 645-2026新国标深度解读与智能电表协议适配实战:从帧结构变化到Java采集器升级的全链路改造方案
java·开发语言
多加点辣也没关系13 小时前
JavaScript|第4章:类型转换
开发语言·javascript
聪慧的水蜜桃13 小时前
【YFIOs】用C#开发硬件之设备上云
开发语言·c#
yqcoder13 小时前
httpOnly 是什么,又有什么用?
开发语言·前端·javascript