zoukankan      html  css  js  c++  java
  • AOP:代理思想 (没有考虑到Spring)

    文件目录:

    package com.wangcf.entity;
    
    public class User {
        private int id;
        private String name;
        private String password;
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        
    }

    想要执行的方法:

    package com.wangcf.manager;
    
    import com.wangcf.entity.User;
    
    public class UserManager {
        
        private LogManager logManger;
        private AuthorityManager autManager;
        public UserManager(){
            this.logManger=new LogManager();
            this.autManager=new AuthorityManager();
        }
        
        public void add(User user){
            autManager.isAllown();
            logManger.add();
            System.out.println("UserManager add...");
        }
        
        public void del(User user){
            autManager.isAllown();
            logManger.add();
            System.out.println("UserManager del...");
        }
        
        public void update(User user){
            autManager.isAllown();
            logManger.add();
            System.out.println("UserManager update...");
        }
    }

    切面拦截,

    package com.wangcf.manager;
    
    public class AuthorityManager {
        public boolean isAllown(){
            boolean flag=true;
            System.out.println("权限检查..");
            return true;
        }
    }
    
    package com.wangcf.manager;
    
    public class LogManager {
        
        public void add(){
            System.out.println("添加日志...");
        }
    }

    测试类:

    package com.wangcf.test;
    
    import com.wangcf.manager.UserManager;
    
    public class testAction {
        public static void main(String[] args) {
            UserManager userManager=new UserManager();
            userManager.add(null);
        }
    }

    输出:

     参考网页:http://wenku.baidu.com/view/29320a66a9956bec0975f46527d3240c8447a1be.html

  • 相关阅读:
    Android入门:DDMS视图
    Android入门:EditText
    Hibernate入门:关联规则之多对一和一对多
    MyEclipse开发Rest服务入门
    Hibernate入门:使用C3P0连接池
    InfoQ:深入浅出REST
    二维码的编码与解码辅助类
    Android系统Resource之Drawable
    Android开发中的点滴
    粒子效果的简单实现
  • 原文地址:https://www.cnblogs.com/-beauTiFul/p/6289555.html
Copyright © 2011-2022 走看看