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);
    }
}
相关推荐
hfywmsj4 分钟前
广州餐饮铺位招租决策模型:多因子选址系统设计
开发语言·人工智能·python·广州餐饮铺位招租
努力的lpp2 小时前
php反序列化一(大白话版)
开发语言·web安全·php·ctf·反序列化
菜鸟~noob2332 小时前
【电子战】第03篇:CFAR(恒虚警)处理【含matlab代码】
开发语言·matlab
lhldsg3 小时前
全民健身解决方案小程序开发:从0到1的技术实战
java·数据库·需求分析
jason成都3 小时前
Spring WebFlux 适配达梦新方案|dm‑r2dbc:Netty 异步传输的实验性 R2DBC 驱动
java·后端·spring
泡海椒3 小时前
内置SPI函数库详解:JQuick-Java Builtin工具类实战用法
java·开发语言·python
hqyjzsb3 小时前
零 AI 项目经验,学 Python 转型 AI 的正确顺序是什么?
开发语言·人工智能·python·算法·职场和发展·数据挖掘·数据分析
辰烨chenye3 小时前
LeetCode Hot 100 题解 · 二分篇
java·算法·leetcode
小羊没烦恼!4 小时前
Hello Web API系列教程——Web API与国际化
java·服务器·前端·javascript·php
Keven_114 小时前
算法札记:ACM适用的很骚的C++语法(持续更新)
开发语言·c++