zoukankan      html  css  js  c++  java
  • java AOP 面向切面编程例子

    1. pom 引入aop jar


    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>


    2. 定义切面 Aspect


    @Aspect
    @Component // 这句不能少
    public class TestAspect {
      private Logger logger = Logger.getLogger(getClass());

      @Pointcut("execution(* com.test.server1.controller.ComputerController.test(..))")
      public void testPoint() {}

      @Before(value="testPoint()")
      public void handleBeforeMethod()
      {
      logger.info("handleBeforeMethod before");
      }

      @Around(value = "testPoint()")
      public String handleAroundMethod(ProceedingJoinPoint joinPoint) throws Throwable
      {
      logger.info("handleAroundMethod Around");
      return (String) joinPoint.proceed();
      }

      @After(value = "testPoint()")
      public void handleAfterMethod()
      {
      logger.info("handleAfterMethod After");
      }

    }

  • 相关阅读:
    hbase 得到一行的数据详情
    文件上传
    es 启动用户
    es 分片丢失
    es 调整查询窗口
    hbase 字段值开头查询
    maven 项目linux运行可执行jar
    hbase count 扫表查询
    hbase 查询空串空字段
    sql常用手法(二)
  • 原文地址:https://www.cnblogs.com/xiangjune/p/6807998.html
Copyright © 2011-2022 走看看