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);
    }
}
相关推荐
唐青枫11 小时前
Java JDBC 实战指南:从 Connection 到事务和连接池
java
一个做软件开发的牛马13 小时前
MyBatis-Plus 从零实战:完整搭建可运行 Demo,BaseMapper 零 SQL、Wrapper 条件构造、分页插件与代码生成器详解
java·后端
用户37215742613513 小时前
Java 处理 PDF 图片:提取 PDF 中的图片,并压缩 PDF 图片体积
java
用户37215742613513 小时前
Java 打印 Word 文档:从基础打印到高级设置
java
用户3521802454751 天前
当 Prompt 学会"热更新":Spring Boot × Nacos3 AI 实战
java·spring boot·ai编程
东坡白菜1 天前
破局全栈:一个前端开发的Java入门实战记录(1)
java·全栈
唐青枫1 天前
Java Tomcat 实战指南:从 Servlet 容器到 Spring Boot 部署
java
wsaaaqqq1 天前
roudan:自由选择实体、灵活操作数据、快速写入数据库的 Java 框架
java
plainGeekDev1 天前
null 判断 → Kotlin 可空类型
android·java·kotlin
糖拌西瓜皮1 天前
Java开发者视角:深入理解Node.js异步编程模型
java·后端·node.js