AOP:代理思想 (没有考虑到Spring)

时间:2023-03-09 19:52:48
AOP:代理思想 (没有考虑到Spring)

文件目录:

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);
}
}

输出:

AOP:代理思想 (没有考虑到Spring)

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