动态代理例子(二)

 

被代理对象接口定义

 

public interface UserManager {

	public void aadUser(User user);
	
	public void deleteById(int id);
	
	public void updateUser(User user);
	
	public User findById(int id);
}

 

 被代理对象接口实现

 

public class UserManagerImp implements UserManager {
	@Override
	public void aadUser(User user) {
		System.out.println("----------addUser------------");
	}
	@Override
	public void deleteById(int id) {
		System.out.println("----------deleteById------------");
	}
	@Override
	public User findById(int id) {
		System.out.println("----------findById------------");
		return null;
	}
	@Override
	public void updateUser(User user) {
		System.out.println("----------updateUser------------");
	}
}

 

 定义一个user对象

 

public class User {
	private int id;
	private String name;
	private int age;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
}

 

posted @ 2012-01-06 19:23  胖鹅  阅读(152)  评论(0编辑  收藏  举报