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

能够做外贸的网站有哪些问题近三天新闻50字左右

能够做外贸的网站有哪些问题,近三天新闻50字左右,上海解封最新消息,网站开发90天代码地址 https://github.com/cmdch2017/JDKproxy.git/ 我的理解 我的理解是本身service-serviceImpl结构,新增一个代理对象proxy,代理对象去直接访问serviceImpl,在proxy进行事务的增强操作,所以代理对象实现了接口。如何实现…

代码地址

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 transaction=new DaoTransaction();StudentServiceImpl studentService=new StudentServiceImpl();TransactionHandler transactionHandler=new TransactionHandler(studentService,transaction);StudentService proxyInstance=(StudentService)Proxy.newProxyInstance(StudentServiceImpl.class.getClassLoader(),StudentServiceImpl.class.getInterfaces(),transactionHandler);Student student=proxyInstance.query(id);System.out.println("id:"+student.getId()+",name:"+student.getName());}
//这里是静态代理private static void testQuery(int id) {DaoTransaction transaction=new DaoTransaction();StudentServiceImpl studentService=new StudentServiceImpl();ProxyStudent proxyStudent=new ProxyStudent(studentService,transaction);Student student=proxyStudent.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 student=studentService.query(id);daoTransaction.endTransaction();return student;}
}
public class StudentServiceImpl implements StudentService {@Overridepublic Student query(int id) {System.out.println("执行查询");Student student=new 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.mmbaike.com/news/39737.html

相关文章:

  • 网站建设先做前台还是后台2023年5月疫情爆发
  • 广州网站建设制作价格怎么去营销自己的产品
  • 网站空间如何升级360推广怎么收费
  • 网站查询页面设计长春网站制作推广
  • 企业开发网站建设百度广告代运营公司
  • 三亚文明城市建设服务中心报名网站关键词搜索次数查询
  • 空间设计师网站链网
  • 公司运营策划方案seo公司
  • 建设公司网站的好处手机百度电脑版入口
  • 重庆汉沙科技做网站怎么样网络营销的企业有哪些
  • 网站建设的策划模板网站免费
  • 有没有做装修的大型网站而不是平台搜索引擎是什么意思
  • 新塘17网站一起做网店官网二级域名免费分发
  • 做网站 提要求怎么注册网址
  • 怎样做淘宝的导购网站活动软文怎么写
  • a站网址中国最新军事新闻
  • 网站建设 软件开发的公司哈尔滨最新消息
  • 免费网站建设报价公司网络营销策略
  • 一个公网ip可以做几个网站优化大师windows
  • 动态网站怎么做天津网站优化
  • 国字型网站建设布局优秀网站设计网站
  • 郑州做网站那新的营销模式有哪些
  • 在凡科上做的网站无法加载出来百度指数首页
  • seo短视频网页入口引流在线看郑州网站优化哪家好
  • 国外建站网址泰州seo网站推广
  • 百度推广对网站的好处百度seo关键词排名查询工具
  • 找做网站技术人员高手优化网站
  • 网站权限设置郑州seo排名公司
  • 企业管理网站的来历百度seo关键词排名技术
  • 做网站为什么要用固定ip全网营销型网站