springboot参数_spring的aop是什么

springboot参数_spring的aop是什么springaop参数传递

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺


spring aop参数传递

        

              

                             

使用示例

        

                           springboot参数_spring的aop是什么

            

HelloService

public interface HelloService {

    String hello();
    String hello(String name);
    String hello(String name, Integer age);
}

       

HelloServiceImpl

@Service
public class HelloServiceImpl implements HelloService {

    @Override
    public String hello() {
        return "hello";
    }

    @Override
    public String hello(String name) {
        return "hello " + name;
    }

    @Override
    public String hello(String name, Integer age) {
        return "hello " + name + " " + age;
    }
}

         

CustomAspect

@Aspect
@Component
public class CustomAspect {

    @Pointcut("execution(* *.hello(..))")
    public void fun(){

    }

    @Pointcut("execution(* *.hello(String)) && args(name))")
    public void fun2(String name){

    }
    @Pointcut("execution(* *.hello(String,..)) && args(name))")
    public void fun3(String name){

    }

    @Pointcut("execution(* *.hello(String,Integer)) && args(name,age)")
    public void fun4(String name, Integer age){

    }

    @Before("fun()")
    public void before(JoinPoint joinPoint){
        System.out.print("before ==> ");
        process(joinPoint);
    }

    @Before("fun2(name)")
    public void before2(JoinPoint joinPoint,String name){
        System.out.print("before2 ==> " + name + " ==> ");
        process(joinPoint);
    }

    @Before("fun3(name)")
    public void after3(JoinPoint joinPoint,String name){
        System.out.print("after3 ==> "+ name + " ==> ");
        process(joinPoint);
    }

    @After("fun4(name,age)")
    public void after4(JoinPoint joinPoint, String name, Integer age){
        System.out.print("after4 ==> "+ name + " " +age + " ==> ");
        process(joinPoint);
    }

    public void process(JoinPoint joinPoint){
        MethodSignature signature =(MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        System.out.println(method.getDeclaringClass().getName()+"."+method.getName()+":被调用");
    }
}

           

 HelloController

@RestController
public class HelloController {

    @Resource
    private HelloService helloService;

    @RequestMapping("/hello")
    public String hello(){
        return helloService.hello();
    }

    @RequestMapping("/hello2")
    public String hello2(){
        return helloService.hello("瓜田李下");
    }

    @RequestMapping("/hello3")
    public String hello3(){
        return helloService.hello("瓜田李下",20);
    }
}

        

            

                             

使用示例

      

localhost:8080/hello,控制台输出:

before ==> com.example.demo.controller.HelloController.hello:被调用
before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用

        

localhost:8080/hello2,控制台输出:

after3 ==> 瓜田李下 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
before2 ==> 瓜田李下 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用

       

localhost:8080/hello3,控制台输出:

before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
after4 ==> 瓜田李下 20 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用

        

               

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/169626.html原文链接:https://javaforall.net

(0)
上一篇 2022年8月11日 下午1:16
下一篇 2022年8月11日 下午1:16


相关推荐

  • C++ rapidjson 使用

    C++ rapidjson 使用转 JSONrapidjso Documentdocu document SetObject 添加 name valueconstch name success url constchar value https www google com document AddMember rapidjson StringRef name rapidjson StringRef value document GetAll

    2025年6月9日
    6
  • QSettings中文配置内容

    QSettings中文配置内容1 在工程构架中 我们经常需要接触一些动态会变化的信息 比如所要链接数据库的信息 所要接收发送信息的服务器的信息 甚至是自定义的一些字符串 如果都将这个写入代码 显然不是好的方法 于是 我们将这些可能会变的信息写入一个配置文件 程序在运行的时候动态的读取 降低工程耦合度 以我自己写的一个测试程序为例子 defineAppCon MyAppConfig ini defineAppLo

    2026年3月18日
    3
  • Java学习之Maven使用

    Java学习之Maven0x00前言学习并mark过来一些知识点做留存。0x01Maven使用compiled(默认)对主程序是否有效:有效对测试程序是否有效:有效是否参与打包:参

    2021年12月13日
    37
  • 快速接入豆包大模型API的实战经验分享

    快速接入豆包大模型API的实战经验分享

    2026年3月12日
    2
  • padEnd_np.pad函数

    padEnd_np.pad函数ES2017引入了字符串补全长度的功能。如果某个字符串不够指定长度,会在头部或尾部补全。padStart()用于头部补全,padEnd()用于尾部补全下面有一个小练习身份号只显示后四位

    2025年10月11日
    6
  • intel AVX / AVX2指令学习资源

    intel AVX / AVX2指令学习资源IntelReferenceGuidesIntelIntrinsicsGuide一些解读

    2022年5月30日
    32

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号