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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 贴片机保养步骤 保养项目 保养的目的与作用

    贴片机是一种高强度、长时间、超负荷的运转设备,需要定期进行细心的呵护保养,贴片机保养的好,运转稳定,保证日常生产产能,贴片机如衣食父母;贴片机保养不到位或经常不保养,性能再好的机子也会不堪重负出现各类毛病,影响生产产能和产品质量,因此贴片机保养是贴片厂非常重要的一环工作内容事项。(延伸阅读:何为SMT?smt是做什么的,smt贴片是什么意思?)贴片机日保用干净白布清洁机器表面灰尘,包含机身、显示器、键盘、鼠标、开关等;检测气压正常值;检查机器内部各装置是否正常;用吸尘器清洁机器里

    2022年4月7日
    38
  • 什么是线程? [通俗易懂]

    什么是线程? [通俗易懂]所有重要的操作系统都支持进程的概念–独立运行的程序,在某种程度上相互隔离。线程有时称为轻量级进程。与进程一样,它们拥有通过程序运行的独立的并发路径,并且每个线程都有自己的程序计数器,称为堆栈

    2022年7月1日
    23
  • [USACO12JAN]视频游戏的连击Video Game Combos「建议收藏」

    很早之前就做过啦补一下题解F(i,j)前i个的字符为j的匹配注意end要累加#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<queue>usingnam…

    2022年4月10日
    45
  • java大数据开发需要掌握什么_大数据要学java吗

    java大数据开发需要掌握什么_大数据要学java吗​​​​​​你想过自己的未来规划吗?java大数据程序员只需要学到技术就行吗?1.如何成为大数据工程师Java开发是IT行业的经典岗位,行业当中存在普遍的需求,Web开发、Android开发、游戏开发等基本上Java语言是主力队伍。而进入大数据时代,Java又在大数据方向上有了用武之地,又该如何进行成长路线规划。在Java程序界流行着一种默认的说法叫黄金5年,也就是一个程序员从入职的时候开始算起,前五年的选择直接影响着整个职业生涯中的职业发展方向和薪资走向。2014年8月,阿里巴巴举办了

    2022年10月19日
    3
  • CAP原理通俗理解「建议收藏」

    CAP原理通俗理解「建议收藏」在分布式系统中,有一个基本原则叫做CAP,consistence,一致性,availability,可用性,partitiontolerance分区容错性。 一致性,在这里指的是分布式系统的各个副本的值要保持同步,这里强的是空间上的一致,注意和数据库中ACID中的一致性相区分,那个一致性指的是事务执行前后的逻辑一致性,比如你转1000块给别人,不能你的账户少了1000块,对方的账户却没有多10…

    2022年5月12日
    47
  • Python系列教程一Python入门(一)

    Python系列教程一Python入门(一)前言各位看博客的园友们,大家好,我就是那个风流倜傥的KK,还记得我那篇2019年的年中总结博客吗?我想有许多看博客的园友是没有读过我那篇文章的,KK很生气,后果很严重(开个玩笑了,怎么可能)。给大家

    2022年7月6日
    27

发表回复

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

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