当前位置: 首页 > news >正文

能打开的网站你了解的企业网站系统设计与实现

能打开的网站你了解的,企业网站系统设计与实现,佛山市城乡住房建设局网站,网站必须兼容哪些浏览器代码地址 https://github.com/cmdch2017/JDKproxy.git/ 我的理解 我的理解是本身service-serviceImpl结构#xff0c;新增一个代理对象proxy#xff0c;代理对象去直接访问serviceImpl#xff0c;在proxy进行事务的增强操作#xff0c;所以代理对象实现了接口。如何实现…代码地址 https://github.com/cmdch2017/JDKproxy.git/ 我的理解 我的理解是本身service-serviceImpl结构新增一个代理对象proxy代理对象去直接访问serviceImpl在proxy进行事务的增强操作所以代理对象实现了接口。如何实现动态呢需要实现InovacationHandler接口并用反射调用invoke方法实现类似于泛型一样的效果。 CHATGPT回答 “JDK动态代理是通过Proxy类和InvocationHandler接口实现的。它允许在运行时生成代理类无需事先定义代理类从而在不修改原有代码的情况下对方法进行增强。通过实现InvocationHandler接口我们可以在目标方法执行前后插入自定义逻辑比如事务处理。动态代理的优势在于避免了手动创建大量代理类的繁琐工作使代码更加简洁和易维护。” 核心代码 客户端 public class TestStudent {public static void main(String[] args) { // testQuery(1);testQueryObject(1);} //这里是动态代理多实现了一个InvocationHandlerprivate static void testQueryObject(int id) {DaoTransaction transactionnew DaoTransaction();StudentServiceImpl studentServicenew StudentServiceImpl();TransactionHandler transactionHandlernew TransactionHandler(studentService,transaction);StudentService proxyInstance(StudentService)Proxy.newProxyInstance(StudentServiceImpl.class.getClassLoader(),StudentServiceImpl.class.getInterfaces(),transactionHandler);Student studentproxyInstance.query(id);System.out.println(id:student.getId(),name:student.getName());} //这里是静态代理private static void testQuery(int id) {DaoTransaction transactionnew DaoTransaction();StudentServiceImpl studentServicenew StudentServiceImpl();ProxyStudent proxyStudentnew ProxyStudent(studentService,transaction);Student studentproxyStudent.query(id);System.out.println(id:student.getId(),name:student.getName());} }动态代理学生 public class TransactionHandler implements InvocationHandler {private DaoTransaction daoTransaction;private Object object;public TransactionHandler(Object object, DaoTransaction daoTransaction) {this.object object;this.daoTransaction daoTransaction;}Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable {return method.invoke(object,args);} }Data public class Student {private int id;private String name; }静态代理学生 public class ProxyStudent implements StudentService {private StudentServiceImpl studentService;private DaoTransaction daoTransaction;public ProxyStudent(StudentServiceImpl studentService, DaoTransaction daoTransaction) {this.studentService studentService;this.daoTransaction daoTransaction;}Overridepublic Student query(int id) {daoTransaction.startTransaction();Student studentstudentService.query(id);daoTransaction.endTransaction();return student;} }public class StudentServiceImpl implements StudentService {Overridepublic Student query(int id) {System.out.println(执行查询);Student studentnew Student();student.setId(id);student.setName(lst);return student;} }public interface StudentService {Student query(int id); } public class DaoTransaction {public void startTransaction() {System.out.println(开启事务);}public void endTransaction() {System.out.println(关闭事务);} }
http://www.hkea.cn/news/14296537/

相关文章:

  • 佛山新网站建设价格wordpress口塞
  • 文山网站建设联系电话电商小程序模板
  • 课程网站开发开题报告网站项目报价方案
  • 公司介绍网站平台搭建设计论文wap网站还有能打开的吗
  • 自己有域名服务器怎样建设网站wordpress模板title属性
  • 旅行社网站建设哪家好可以做设计兼职的网站
  • 大兴区住房和城乡建设部网站长春seo网站优化
  • 闸北做网站公司杭州手机申请网站登录
  • 品牌网站建设设计公司贵溪网站建设
  • 怎么夸客户网站做的好江西汽车网站建设
  • 北京网站排名公司网站关闭公告代码
  • 做网站的去那里接单广告设计培训班有用吗
  • 二级网站建设方案 试行什么平台可以发广告引流
  • 做一个公司的网站应做哪些准备工作内容单位做好接种第三针疫苗通知
  • asp.net网站搬迁到移动终端网站建设的工作方法
  • 网站上推广游戏怎么做wordpress所有标签编辑目录
  • 韩国ps教程网站数商云公司
  • 网站界面怎么做有限公司名称大全
  • 淮南建设网站公益网站模板
  • 各大网站logo图标网络工程和软件工程哪个好
  • 企业网站建设合同抖音广告投放代理商
  • 网站禁止访问网站公司建设个服务号多少钱
  • 云南网站开发公司推荐杭州网站建设技术支持
  • 网站分页代码网站集约化建设困难
  • 做任务什么网站查域名备案信息
  • 微信网站模块免费拥有自己的网站
  • 成都网站维护公司山西省建设工程信息网
  • 人像摄影作品网站温州网论坛
  • 请为hs公司的钻石礼品网站做网络营销沟通策划_预算是20万.在线制作电子印章软件
  • 大型地方门户网站源码如何做网站服务