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

做个游戏网站多少钱代发货网站建设

做个游戏网站多少钱,代发货网站建设,该如何建设和优化一个网站,网上服务大厅12333文章目录 使用javassist动态生成类使用javassist动态生成类并实现接口实现接口中所有的方法工具类GenerateDaoProxy的编写 使用javassist动态生成类 Testpublic void testGennerateFirstClass() throws Exception{//获取类池#xff0c;这个类池就是用来生成class的ClassPool … 文章目录 使用javassist动态生成类使用javassist动态生成类并实现接口实现接口中所有的方法工具类GenerateDaoProxy的编写 使用javassist动态生成类 Testpublic void testGennerateFirstClass() throws Exception{//获取类池这个类池就是用来生成class的ClassPool pool ClassPool.getDefault();//制造类需要告诉javassist类名是啥CtClass ctClass pool.makeClass(类名);//制造方法String methodCode publi coid insert(){System.out.println(123);};CtMethod ctMethod CtMethod.make(methodCode, ctClass);//将方法添加到类中ctClass.addMethod(ctMethod);//在内存中生成classctClass.toClass();//类加载到JVM当中返回类的字节码Class? clazz Class.forName(类名);//创建对象Object obj clazz.newInstance();//获取类中的方法Method insertMethod clazz.getDeclaredMethod(insert);//调用方法insertinsertMethod.invoke(obj);}使用javassist动态生成类并实现接口 Testpublic void testGenerateImpl() throws Exception{//获取类池ClassPool pool ClassPool.getDefault();//制造类CtClass ctClass pool.makeClass(类地址)//制造接口CtClass ctInterface pool.makeInterface(类接口地址);// 添加接口到类中ctClass.addInterface(ctInterface);//实现接口中的方法//制造方法CtMethod ctMethod CtMethod.make(条件执行语句,ctClass);//将方法添加到类中ctClass.addMethod(ctMethod);//在内存中生成类同时将生成的类加载到JVM当中。Class? clazz ctClass.toClass();AccountDao accountDao (AccountDao) clazz.newInstance();accountDao.delete();}实现接口中所有的方法 public class javassistTest {Testpublic void testGenerateAccountDaoImpl() throws Exception{//获取类池ClassPool pool ClassPool.getDefault();//制造类CtClass ctClass pool.makeClass(类名地址);//制造接口CtClass ctInterface pool.makeInterface(接口地址);//实现接口ctClass.addInterface(ctInterface);//实现接口中所有的方法Method[] methods AccountDao.class.getDeclaredMethods();Arrays.stream(methods).forEach(method - {//method是接口中的抽象方法//把method抽象方法给实现了try{//public void delete(){}//public int update(String actno, Double balance){}StringBuilder methodCode new StringBuilder();methodCode.append(public);//追加修饰符列表methodCode.append(method.getReturnType().getName());//追加返回值类型methodCode.append( );methodCode.append(method.getName());//追加方法名methodCode.append(();//拼接参数 String actno Double balanceClass?[] paramterTypes method.getParameterTypes();for (int i 0; i paramterTypes.length; i) {Class? parameterType paramterTypes[i];methodCode.append(parameterType.getName());methodCode.append( );methodCode.append(arg i);if(i ! paramterTypes.length - 1){methodCode.append(,);}}methodCode.append(){System.out.println(1111);return 1;}});//动态的添加return语句String returnTypeSimpleName method.getReturnType().getSimpleName();if (void.equals(returnTypeSimpleName)){}else if (int.equals(returnTypeSimpleName)){methodCode.append(return 1;);}else if(String.equals(returnTypeSimpleName)){methodCode.append(return \hello\;);}methodCode.append(});System.out.println(methodCode);CtMethod ctMethod CtMethod.make(methodCode.toString(), ctClass);ctClass.addMethod(ctMethod);}catch (Exception e){e.printStackTrace();}});//在内存中生成class并且加载到JVM当中Class? clazz ctClass.toClass();//创建对象AccountDao accountDao (AccountDao) clazz.newInstance();//调用方法//...}工具类GenerateDaoProxy的编写 package com.example.bank.utils;import org.apache.ibatis.javassist.ClassPool; import org.apache.ibatis.javassist.CtClass; import org.apache.ibatis.javassist.CtMethod; import org.apache.ibatis.mapping.SqlCommandType; import org.apache.ibatis.session.SqlSession;import java.lang.reflect.Method; import java.util.Arrays;public class GenerateDaoProxy{public static Object generate(SqlSession sqlSession, Class daoInterface){//获取类池ClassPool pool ClassPool.getDefault();//制造类CtClass ctClass pool.makeClass(daoInterface.getName() Proxy);//制造接口CtClass ctInterface pool.makeInterface(daoInterface.getName());//实现接口ctClass.addInterface(ctInterface);//实现接口中所有的方法Method[] methods daoInterface.getDeclaredMethods();Arrays.stream(methods).forEach(method - {//method是抽象方法//将method这个抽象方法进行实现try{// Account selectBtActno(String actno);//public Account selectByActno(String arg0, int arg1, int arg2){代码; }StringBuilder methodCode new StringBuilder();methodCode.append(public );methodCode.append(method.getReturnType().getName());methodCode.append( );methodCode.append(method.getName());methodCode.append(();//需要方法的形式参数列表Class?[] paramterTypes method.getParameterTypes();for(int i 0; i paramterTypes.length; i){Class? paramterType paramterTypes[i];methodCode.append(paramterType.getName());methodCode.append( );methodCode.append(arg i);if(i ! paramterTypes.length - 1){methodCode.append(,);}}methodCode.append());methodCode.append({);//需要方法体当中的代码methodCode.append(org.apache.ibatis.session.SqlSession sqlSession com.example.bank.utils.SqlSessionUtil.openSession(););//需要知道是什么类型的sql语句//sql语句的id是框架使用者提供的具有多变性等于我框架的开发人员来说我不知道//既然我框架开发者不知道sqlId怎么办呢mybatis框架的开发者于是就出台了一个归档凡是使用GenerateDaoProxy机制的。//sqlId都不能随便写namespace必须是dao接口的全限定名称id必须是dao接口中的方法名String sqlId daoInterface.getName() . method.getName();SqlCommandType sqlCommandType sqlSession.getConfiguration().getMappedStatement(sqlId).getSqlCommandType();if(sqlCommandType SqlCommandType.INSERT){}if(sqlCommandType SqlCommandType.DELETE){}if(sqlCommandType SqlCommandType.UPDATE){methodCode.append(return sqlSession.update(\sqlId\,arg0););}if(sqlCommandType SqlCommandType.SELECT){String returnType method.getReturnType().getName();methodCode.append(return (returnType) sqlSession.selectOne(\sqlId\,arg0););}methodCode.append(});CtMethod ctMethod CtMethod.make(methodCode.toString(), ctClass);ctClass.addMethod(ctMethod);}catch(Exception e){e.printStackTrace();}});//创建对象Object obj null;try{Class? clazz ctClass.toClass();obj clazz.newInstance();} catch (Exception e){e.printStackTrace();}return obj;} }
http://www.yutouwan.com/news/43477/

相关文章:

  • 当当网站建设的目标703804温州论坛
  • wordpress 导航站模板下载滁州建设网站公司
  • 网站建设制作设计营销 上海域名被墙查询检测
  • 长沙口碑好的做网站公司哪家好亚马逊跨境电商怎么开店
  • 台州网站设计公司网站centos 6.5 wordpress
  • 鱼头seo推广长沙百家号seo
  • 国展网站建设saas建站是什么意思
  • 求职简历在哪个网站做网页设计颜色代码表
  • 怎么学做一件完整衣服网站wordpress 添加下载页面
  • 一级a做爰片免费网站 新闻ui网页设计高手
  • 分销网站wordpress工作室主题
  • 平原网站建设公司汉中做网站电话
  • 郴州网站seo外包百度关键词优化手段
  • 网站会员等级审核功能怎么做小程序定制公司外包
  • 上海网站建设开发哪家专业做网站推广的销售发的朋友圈
  • 怎么做全民夺宝网站dedecms网站入侵
  • 品牌网站建设哪家好如企业网站模板下载
  • 资源收费网站怎么做兰州哪有建设网站的
  • 南昌网站建设培训班wordpress清除原图
  • 南京代做网站网络运营需要学什么
  • 制作网站的知识企业网站建设的意义
  • 网站制作建站建设银行官方网站面试详细信息
  • 牡丹江0453免费信息网站北京公司网站设计价格
  • 常德网站建设设计网站公司图片
  • 网站开发pc和手机端好的html5网站
  • 网站建设及管理网站知识网站
  • 东莞建站多少钱微分销系统开发那家好
  • 营销型科技网站网站建设设计公司类网站织梦模板 带手机端
  • 酒业网站建设如何用代码制作网站
  • 营销型网站推广服务WordPress验证邮箱