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);
    }
}
相关推荐
m0_734172421 小时前
Python列表切片为什么不改变原列表
java
kiss strong1 小时前
idea显示前进后退按钮
java·ide·intellij-idea
“AI国潮设计-小江”2 小时前
【SDXL实战】用AI生成“财神爷蛋糕×英歌舞人物”潮汕国潮甜品IP,附Prompt与批量生成思路
开发语言·人工智能·python·aigc
繁华的地方不一定留下你的脚印2 小时前
C++线程如何安全停止与唤醒:std::jthread、stop_token与condition_variable
开发语言·c++
caoerzhong2 小时前
跨境海外仓怎么管:JeeWMS 开源 Java 仓库管理系统打通头程、海外仓与尾程
java·开发语言·开源
码云数智-大飞2 小时前
新手写 Python 代码,如何规范命名、减少 Bug
开发语言·python·php
MayBaymax2 小时前
Elasticsearch 原理与用法
java·elasticsearch
马剑威(威哥爱编程)2 小时前
【AI全栈后端12-02】Spring Boot 跑通第一个 AI 对话接口:HR 政策问答机器人实战
java·人工智能·spring boot·机器人
IT枫斗者枫哥2 小时前
AI返回合法JSON,字段就可信吗?给抽取结果补一道业务校验
java·人工智能·后端
用户3126874877202 小时前
Java IO/NIO/AIO 演进:从 BIO 到 Netty 的底层逻辑
java