企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
静态代理 ``` 程序运行前已经存在代理类的字节码文件,代理类和委托类的关系在运行前就确定了 ``` 示例: IUserDao ~~~ public interface IUserDao { void save(); } ~~~ IUserDaoImpl ~~~ public class IUserDaoImpl implements IUserDao { @Override public void save() { System.out.println("保存数据"); } } ~~~ UserDaoProxy ~~~ public class UserDaoProxy implements IUserDao { private IUserDao target; public UserDaoProxy(IUserDao target) { this.target = target; } @Override public void save() { System.out.println("保存前....."); target.save(); System.out.println("保存后....."); } } ~~~ 测试 ~~~ IUserDao iUserDao = new IUserDaoImpl(); UserDaoProxy proxy = new UserDaoProxy(iUserDao); proxy.save(); ~~~ 保存前..... 保存数据 保存后.....