代理模式02
1、接口类
import java.lang.reflect.Method;
/*系统功能的建议,spring中命名规则*/
public interface Advice {
?public void beforeMethod(Method method);
?public void afterMethod(Method method);
?public String CMethod();
}
2、接口的实现类,用来对代理前后进行操作的
import java.lang.reflect.Method;
public class MyAdvice implements Advice {
?long beginTime = 0;
?long endTime = 0;
?public void afterMethod(Method method) {
??System.out.println("结束时间");
?? endTime = System.currentTimeMillis();//获取毫秒信息
?? System.out.println(CMethod());
?}
?public void beforeMethod(Method method) {
??System.out.println("开始时间");
??beginTime = System.currentTimeMillis();
?}
?
?public String CMethod(){
??return "总共用时" + (beginTime - endTime) ;
?}
}
3、调用代理模式01中的getProxy()方法即刻实现代理