静态代理
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 ( ) ;
}
}