• aspectj 简单的模拟权限检查、事务、日志记录


    package com.ij34.service;
    
    
    public class Hello
    {
        public void he()
        {
            System.out.println("执行Hello的he方法");
        }
        public int addUser(String name , String pass)
        {
            System.out.println("执行Hello的addUser方法:" + name);
            return 0;
        }
    }
    View Code
    package com.ij34.service;
    
    
    public class Hi
    {
    
        public void hihi()
        {
            System.out.println("执行Hi组件的hihi()方法");
        }
    }
    View Code

    package com.ij34.bean;
    
    import com.ij34.service.*;
    
    public class Aspecttest
    {
        public static void main(String[] args)
        {
            Hello hello = new Hello();
            hello.he();
            hello.addUser("尼古拉特斯拉" , "");
            Hi hi = new Hi();
            hi.hihi();
        }
    }
    View Code

    package com.ij34.aspect;
    
    public aspect AuthAspect {
      before() : execution(* com.ij34.service .*.*(..)) {
          System.out.println("模拟进行权限检查");
      }
    }
    package com.ij34.aspect;
    
    
    public aspect Logaspect {
       pointcut log() 
           : execution(* com.ij34.service .*.*(..));
       after(): log(){
           System.out.println("模拟日志记录...");
       }
    
        }
    package com.ij34.aspect;
    
    public aspect TextAspect {
      Object around(): call(* com.ij34.service .*.*(..)){
          System.out.println("模拟开始事务... ");
           Object o=proceed();
           System.out.println("结束模拟事务");
           return o;
      }
      
    }
  • 相关阅读:
    requirejs
    fontresize 移动端的手机字体 大小设置
    css 设置字体
    nodejs javascript微信开发
    多个倒计时
    pure.css 学习记录
    【转】JMeter学习(五)检查点(断言)
    【转】JMeter学习(四)参数化
    【转】JMeter学习(三)元件的作用域与执行顺序
    [转]JMeter学习(二)录制脚本
  • 原文地址:https://www.cnblogs.com/tk55/p/6514961.html
Copyright © 2020-2023  润新知