多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ public class JdkProxy implements InvocationHandler { private Object target; public JdkProxy(Object target) { this.target = target; } @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = null; System.out.println("before"); result = method.invoke(target, args); System.out.println("after"); return result; } } ~~~ ~~~ // 传入被代理对象 IUserDao userDao = new UserDaoImpl(); JdkProxy jdkProxy = new JdkProxy(userDao); ClassLoader classLoader = userDao.getClass().getClassLoader(); Class<?>[] interfaces = userDao.getClass().getInterfaces(); IUserDao newProxyInstanc = (IUserDao)Proxy.newProxyInstance(classLoader, interfaces, jdkProxy); newProxyInstanc.save(); ~~~