href="http://www.cnblogs.com/hongten/gallery/image/112445.HTML">http://www.cnblogs.com/hongten/gallery/image/112445.HTML
> 代理对象 -------------->> 目标对象
com.b510.service; PersonService { save(String name); String getPersonname(Integer personID); update(String name,Integer personID); }
com.b510.service.impl; java.lang.reflect.InvocationHandler; java.lang.reflect.Method; java.lang.reflect.Proxy; JDKProxyFactory InvocationHandler { Object targetobject; Object createProxyInstance(Object targetobject) { .targetobject = targetobject; Proxy.newProxyInstance(.targetobject.getClass() .getClassLoader(), .targetobject.getClass().getInterfaces(),); } @OverrIDe Object invoke(Object arg0,Method method,Object[] arg) Throwable { PersonServiceBean bean = (PersonServiceBean) .targetobject; Object result = ; (bean.getUser() != ) { result = method.invoke(targetobject,arg); } result; } }
com.b510.service.impl; com.b510.service.PersonService; PersonServiceBean PersonService { String user = ; PersonServiceBean() { } PersonServiceBean(String user) { .user = user; } String getUser() { .user; } @OverrIDe String getPersonname(Integer personID) { System.out.println("this is the getPersonname() function"); "hongten"; } @OverrIDe save(String name) { System.out.println("this is the save() function"); } @OverrIDe update(String name,Integer personID) { System.out.println("this is the update() function"); } }
com.b510.test; com.b510.service.PersonService;