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


相关推荐

  • SQL Server基本操作练习「建议收藏」

    SQL Server基本操作练习「建议收藏」代码实现:use test_0425goselect *from student– 查专业是什么学的select *from studentwhere stspecialty like’%学’– 查分72-87的 并且 专业是什么文的select *from studentwhere stscore like ‘[7-8][2-7]’ and stspecialty …

    2022年8月18日
  • 冒泡排序怎么排_vj5347

    冒泡排序怎么排_vj5347[BZOJ5347]冒泡排序[思维]

    2022年4月21日
  • deepfakes怎么用_手把手教你使用 Deepfakes 换脸

    deepfakes怎么用_手把手教你使用 Deepfakes 换脸做为程序员,不会换脸软件怎么能忍?下面教你们徒手使用Deepfakes换脸。python如何使用Deepfakes换脸?git获取deepfakes工具包程序员gitclonehttps://github.com/deepfakes/faceswap.git补齐依赖包:githubpipinstalltqdmpipinstallcv2pipinstallopencv-c…

    2022年5月26日
  • Linux下route命令用法

    Linux下route命令用法显示现在所有路由#routeroot@ubuntu:~#routeKernelIProutingtableDestination  Gateway    Genmask    FlagsMetricRef  UseIface10.147.9.0   *       255.255.255.0 U  1

    2022年7月18日
  • video operation_open vino

    video operation_open vino转载注明出处:http://zjbintsystem.blog.51cto.com/964211/713240从盛夏走到深秋,我们继续DAVINCIDM365-DM368的开发。说来惭愧,人家51CTO热情支持本博客,而本人却一直没有像其他博客之星一样频繁更新博客,心里确实说不过去。管理公司确实很累,有更急的客户的项目要做,我们成功先推出了DM6446-810MHz的核心板( htt

    2022年8月13日
  • uniapp中使用jsencrypt进行RSA加密,解决密文作为参数传输到后台时+号变成空格的问题「建议收藏」

    uniapp中使用jsencrypt进行RSA加密,解决密文作为参数传输到后台时+号变成空格的问题「建议收藏」解决密文作为参数传输到后台时+号变成空格的问题用encrypt.encrypt()加密后生成的密文字符串中带有加号,如下Q3Q+ZijLMjcKyC1whAzxtfVpy7G+N1kpCGQJYO8dISQ1UyEzczC6vdqbwG18K6ylTv2fXujogOFwzgZlNuVTKEDVeHqjnsYjDcOUJqvE8t8Mxug+vVMnAOsJfzL0eZqYREoq7YoDJ150q7xZB/8XZEfzwnc/4MwKJLHshj+UFCc=密文作为参数传输到后端时+号变成了空格,

    2022年9月4日

发表回复

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

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