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

php网站源码安装教程网站开发工程师asp考试

php网站源码安装教程,网站开发工程师asp考试,淘客的手机网站怎么做,网络技术专业定义一个容器#xff0c;使用ConcurrentHashMap 做为单例对象的容器 先解析beans.xml得到第一个bean对象的信息#xff0c;id#xff0c;class#xff0c;属性和属性值使用反射生成对象#xff0c;并赋值将创建好的bean对象放入到singletonObjects集合中提供getBean(id)方…定义一个容器使用ConcurrentHashMap 做为单例对象的容器 先解析beans.xml得到第一个bean对象的信息idclass属性和属性值使用反射生成对象并赋值将创建好的bean对象放入到singletonObjects集合中提供getBean(id)方法可以返回对应的bean对象 monster bean public class Monster {private Integer id;private String name;private String skill;public Monster() {}public Integer getId() {return id;}public void setId(Integer id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public String getSkill() {return skill;}public void setSkill(String skill) {this.skill skill;}Overridepublic String toString() {return Monster{ id id , name name \ , skill skill \ };} } package com.sparrow.spring.application;import com.sparrow.spring.bean.Monster; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader;import java.io.File; import java.util.List; import java.util.concurrent.ConcurrentHashMap;/*** Author: 诉衷情の麻雀* Description: TODO* DateTime: 2023/7/24 8:09**/ public class SpaApplicationContext {private ConcurrentHashMapString, Object singletonObjects new ConcurrentHashMap();//构造器 接收一个容器的配置文件public SpaApplicationContext(String iocBeanXmlFile) throws Exception {//1. 得到类加载路径String path this.getClass().getResource(/).getPath();//2.创建SaxReaderSAXReader saxReader new SAXReader();//3.得到Document对象Document document saxReader.read(new File(path iocBeanXmlFile));//4.得到rootElementElement rootElement document.getRootElement();ListElement elements rootElement.elements(bean);for (Element bean : elements) {String id bean.attributeValue(id);String classFullPath bean.attributeValue(class);Integer monsterId null;String name ;String skill ;//遍历bean下面的property属性ListElement property bean.elements(property);for (Element elementProperty : property) {//如果是id把值存起来if (id.equalsIgnoreCase(elementProperty.attributeValue(name))) {monsterId Integer.valueOf(elementProperty.attributeValue(value));} else if (name.equalsIgnoreCase(elementProperty.attributeValue(name))) {name elementProperty.attributeValue(value);} else if (skill.equalsIgnoreCase(elementProperty.attributeValue(name))) {skill elementProperty.attributeValue(value);}//利用反射 根据类的全路径 进行实例化Class? aClass Class.forName(classFullPath);Monster o (Monster) aClass.newInstance();o.setId(monsterId);o.setName(name);o.setSkill(skill);//放入容器中singletonObjects.put(id, o);}}}public Object getBean(String id) {return singletonObjects.get(id);} } beans.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdbean classcom.sparrow.spring.bean.Monster idmonster01property nameid value1/property namename value白骨精/property nameskill value吃唐僧//beanbean classcom.sparrow.spring.bean.Monster idmonster02property nameid value2/property namename value老鼠精/property nameskill value吸血//bean/beanspublic class Test {public static void main(String[] args) throws Exception {SpaApplicationContext spaApplicationContext new SpaApplicationContext(beans.xml);Monster monster02 (Monster) spaApplicationContext.getBean(monster02);Monster monster01 (Monster) spaApplicationContext.getBean(monster01);System.out.println(monster02);System.out.println(monster01);} }
http://www.zqtcl.cn/news/837721/

相关文章:

  • 湖北网络营销网站市场营销策划案
  • 政务信息系统网站建设规范上海网站开发制作公司
  • 网站公众平台建设方案湖南seo优化报价
  • 企业网站制作公司discuz 转wordpress
  • 可信网站是什么意思应用软件开发平台
  • 上海市官方网站福建省中嘉建设工程有限公司网站
  • 备案之后怎样把 放到网站上大连建设网球场价格
  • dkp网站开发今天最新新闻
  • 山东省环保厅官方网站建设项目东莞寮步网站设计
  • 网站开发可能遇到的问题附近电脑培训班位置
  • 如何查看域名以前是做什么网站的网站索引下降如何解决
  • 潜江 网站建设扬中话
  • 网站建设项目方案ppt广州建站模板平台
  • 房产部门成立网站免费seo推广软件
  • python做网站好处百度指数分析报告
  • 网站建设挣钱班级介绍网页制作模板
  • 工作室 网站建设app公司
  • 自己做的网站怎么在百度搜索到网页制作论文3000字
  • 如何网站托管中国跨境电商平台有多少
  • 手机p2p网站做平面设计兼职的网站有哪些
  • 贵金属网站建设唐山网站制作工具
  • 网站入门成都网站制作沈阳
  • 接做网站单子的网站做网站要会那些ps
  • 做盗市相关网站wordpress速度优化简书
  • 贵阳手机网站建设公司国内永久免费云服务器
  • 温州做网站定制哪家网络推广公司好
  • 招聘网站怎么做线下活动网站后台管理系统怎么开发
  • 西湖区外贸网站建设商梦建站
  • 网站首页设计注意斗蟋蟀网站建设
  • 石家庄网站建设远策科技网站建设公司人员配备