静态代理
package com.test.staticProxy;
public interface IUsersService {
public void insert();
}
package com.test.staticProxy;
//目标类
public class UsersService implements IUsersService {
@Override
public void insert() {
System.out.println("添加用户");
}
}
package com.test.staticProxy;
import java.util.Date;
//代理类
public class UsersServiceProxy implements IUsersService {
//在代理类中存放一个目标类对象
private IUsersService usersService=new UsersService();
@Override
public void insert() {
System.out.println("添加开始前:"+new Date());
usersService.insert();
System.out.println("添加结束后:"+new Date());
}
}
测试
package com.test.staticProxy;
import org.junit.Test;
public class TestStaticProxy {
@Test
public void test()
{
IUsersService usersService=new UsersServiceProxy();
usersService.insert();
}
}
文章来源地址https://www.toymoban.com/news/detail-682201.html
文章来源:https://www.toymoban.com/news/detail-682201.html
到了这里,关于javaee spring 静态代理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!