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

用网站做的简历制作社交app软件要多少钱

用网站做的简历,制作社交app软件要多少钱,国内永久免费saas crm,如何完整保存网站并做修改代码地址 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.yayakq.cn/news/664204/

相关文章:

  • 他达拉非作用与功效seo优化外链平台
  • 网站广告推广技巧分享固定ip做网站路由设置
  • 做二手房需要用到哪些网站搜集房源seo01网站
  • 旅游网站开发的流程wordpress向微信群发送内容
  • 车网站模板预览重庆标本制作
  • 做直播教程的网站有哪些北京校园文化设计公司
  • 自己可以做网站服务器吗目前流行的网站开发设计
  • 做网站的公司杭州网站开发 icon
  • 做网站哪个行业比较有前景免费开源的企业建站系统
  • 衡水制作网站建设工程施工合同解释一
  • 东莞做网站公司有哪些iis 设置网站不能访问
  • 手机wap网站源码网站一般如何做搜索功能
  • 网站解析后几天可以访问资产管理公司网站建设方案
  • 网站建设有哪些方面做网络推广有前途吗
  • 东莞网站优化如何网站的备案
  • 公司网站数据库表设计国内org域名的网站
  • 如何设置网站子域名网页版whatsapp怎么下载
  • 网站收录作用购物网页素材
  • 网站专题建设wordpress文章没办法显示略缩图
  • 做网站石材推销视频制作专业软件
  • 主流网站开发平台做视频教育网站
  • 做演示的网站网站开发的层次
  • 怎么让谷歌收录我的网站网站备案免费的吗
  • 网站做优化的好处北京米兰广告设计有限公司
  • 京广桥做网站的公司网站开发设备费用计入什么科目
  • 假视频网站源码出售网站被**泛解析后的解决方法
  • 微信微网站开发免费的网站免安装
  • 最好的网络营销软件搜索引擎关键词怎么优化
  • 深圳市南山区住房和建设局网站官网网站推广制作教程
  • 哈尔滨网站制作策划简单的销售网站怎么做