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

可做分析图的地图网站注册网站排名公司

可做分析图的地图网站,注册网站排名公司,长春网站seo报价,网络营销策划是指文章目录 1.基本介绍1.Spring5官网2.API文档3.Spring核心学习内容4.几个重要概念 2.快速入门1.需求分析2.入门案例1.新建Java项目2.导入jar包3.编写Monster.java4.src下编写Spring配置文件1.创建spring配置文件#xff0c;名字随意#xff0c;但是需要放在src下2.创建Spring … 文章目录 1.基本介绍1.Spring5官网2.API文档3.Spring核心学习内容4.几个重要概念 2.快速入门1.需求分析2.入门案例1.新建Java项目2.导入jar包3.编写Monster.java4.src下编写Spring配置文件1.创建spring配置文件名字随意但是需要放在src下2.创建Spring face3.创建Application Context4.编写内容 5.测试SpringBeanTest 3.类加载路径1.代码输出类加载路径2.结果3.解释 3.Spring容器结构剖析1.beanFactory2.beanFactory内的beanDefinitionMap字段3.beanFactory内的singletonObjects字段4.beanFactory内的beanDefinitionNames字段5.练习得到beans.xml中的所有bean对象的id6.小结 4.实现简单Spring基于xml配置程序1.需求分析2.思路分析3.具体实现1.引入dom4j的jar包2.代码实例1.SxsApplicationContext.java2.SxsApplicationContextTest.java3.结果 5.课后练习1.练习一1.问题答案不会报错系统默认分配id 2.代码 2.练习二1.src/beans.xml2.Car.java3.SpringBeanTest.java4.结果 1.基本介绍 1.Spring5官网 官网 2.API文档 3.Spring核心学习内容 4.几个重要概念 2.快速入门 1.需求分析 2.入门案例 1.新建Java项目 2.导入jar包 3.编写Monster.java package com.sxs.spring.bean;/*** Entity* author 孙显圣* version 1.0*/ public class Monster {private Integer monsterId;private String name;private String skill;//无参构造器一定要给底层是反射创建对象public Monster() {}public Monster(Integer monsterId, String name, String skill) {this.monsterId monsterId;this.name name;this.skill skill;}public Integer getMonsterId() {return monsterId;}public void setMonsterId(Integer monsterId) {this.monsterId monsterId;}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{ monsterId monsterId , name name \ , skill skill \ };} } 4.src下编写Spring配置文件 1.创建spring配置文件名字随意但是需要放在src下 2.创建Spring face 3.创建Application Context 4.编写内容 ?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.xsd!--1.配置monster对象2.在beans中可以配置多个bean3.bean表示就是一个java对象4.class属性用于指定类的路径-spring底层使用反射创建5.id属性表示该java对象在spring容器中的id通过id来获取对象6.property namemonsterId value100/用于给该对象的属性赋值--bean classcom.sxs.spring.bean.Monster idmonster01property namemonsterId value100/property namename value牛魔王/property nameskill value芭蕉扇//bean /beans5.测试SpringBeanTest package com.sxs.spring.test;import com.sxs.spring.bean.Monster; import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;/*** author 孙显圣* version 1.0*/ public class SpringBeanTest {Testpublic void getMonster() {//创建容器ApplicationContext,该容器是对应于一个xml配置文件ApplicationContext ioc new ClassPathXmlApplicationContext(beans.xml);//第一种获取bean对象的方式//1.直接获取配置文件中的bean对象不指定泛型Object monster01 ioc.getBean(monster01);//2.这是一个Object类型的方法指向一个monster类型的对象所以需要向下转型Monster monster (Monster) monster01;//3.输出信息System.out.println(monster);//第二种获取bean对象的方式//1.获取配置文件中的bean对象指定泛型则这个方法就是泛型类型的Monster monster011 ioc.getBean(monster01, Monster.class);//2.输出信息System.out.println(monster011);} } 3.类加载路径 1.代码输出类加载路径 //验证类加载路径Testpublic void classPath() {//输出类加载路径System.out.println(this.getClass().getResource(/).getPath());//所以new ClassPathXmlApplicationContext(beans.xml);//相当于获取/D:/Intelij_IDEA_Project/spring/spring/out/production/spring/下的beans.xml}2.结果 3.解释 可以看出读取的实际是spring下面的文件对应于项目中的src下可以理解为在项目中src/就是类加载路径 3.Spring容器结构剖析 1.beanFactory 2.beanFactory内的beanDefinitionMap字段 3.beanFactory内的singletonObjects字段 4.beanFactory内的beanDefinitionNames字段 5.练习得到beans.xml中的所有bean对象的id //获取beans.xml中所有对象的idTestpublic void getAllId() {ApplicationContext ioc new ClassPathXmlApplicationContext(beans.xml);String[] beanDefinitionNames ioc.getBeanDefinitionNames();for (String beanDefinitionName : beanDefinitionNames) {System.out.println(beanDefinitionName);}}6.小结 根据xml文件创建一个对象里面有三个字段 一个存储xml中的bean对象信息一个存储单例bean对象一个存储xml中所有bean对象id 根据xml文件获取容器的执行流程 读取配置文件反射创建bean对象把bean对象放到容器的字段中 4.实现简单Spring基于xml配置程序 1.需求分析 2.思路分析 3.具体实现 1.引入dom4j的jar包 2.代码实例 1.SxsApplicationContext.java package com.sxs.spring.sxsapplicationcontext;import com.sxs.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.Map; import java.util.concurrent.ConcurrentHashMap;/*** 实现ApplicationContext的简单机制** author 孙显圣* version 1.0*/ public class SxsApplicationContext {//存储单例对象的字段private ConcurrentHashMapString, Object singletonObjects new ConcurrentHashMap();//构造器用于读取xml文件默认在src下public SxsApplicationContext(String iocBeanXmlFileName) throws DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException {//获取类路径String path this.getClass().getResource(/).getPath();//dom4j读取文件SAXReader saxReader new SAXReader();Document read saxReader.read(new File(path iocBeanXmlFileName));Element rootElement read.getRootElement();//获取二级元素的第一个Element bean (Element) rootElement.elements(bean).get(0);//获取属性信息String classAllPath bean.attributeValue(class);String id bean.attributeValue(id);//获取元素信息ListElement property bean.elements(property);//遍历获取这里直接简化一下直接获取Integer monsterId Integer.parseInt(property.get(0).attributeValue(value));String name property.get(1).attributeValue(value);String skill property.get(2).attributeValue(value);//反射创建对象Monster对象Class? aClass Class.forName(classAllPath);Monster o (Monster) aClass.newInstance();//为属性赋值o.setMonsterId(monsterId);o.setName(name);o.setSkill(skill);//放到单例对象中singletonObjects.put(id, o);}//提供一个getBean方法获取id对应的bean对象public T T getBean(String id, ClassT aClass) {for (Map.EntryString, Object stringObjectEntry : singletonObjects.entrySet()) {if (stringObjectEntry.getKey().equals(id)) {//返回T类型的bean对象return (T) stringObjectEntry.getValue();}}return null;}} 2.SxsApplicationContextTest.java package com.sxs.spring.sxsapplicationcontext;import com.sxs.spring.bean.Monster; import org.dom4j.DocumentException;/*** author 孙显圣* version 1.0*/ public class SxsApplicationContextTest {public static void main(String[] args) throws DocumentException, ClassNotFoundException, InstantiationException, IllegalAccessException {SxsApplicationContext sxsApplicationContext new SxsApplicationContext(beans.xml);//获取bean对象Monster monster01 sxsApplicationContext.getBean(monster01, Monster.class);System.out.println(monster01);} } 3.结果 5.课后练习 1.练习一 1.问题答案 不会报错系统默认分配id 2.代码 //得到系统默认分配的id并且得到bean对象Testpublic void getDefaultIdToFindBean() {ApplicationContext ioc new ClassPathXmlApplicationContext(beans.xml);//获取所有bean对象String[] beanDefinitionNames ioc.getBeanDefinitionNames();for (String beanDefinitionName : beanDefinitionNames) {System.out.println(ioc.getBean(beanDefinitionName));}}2.练习二 1.src/beans.xml bean classcom.sxs.spring.bean.Car idcarproperty namename value奔驰/property nameid value100/property nameprice value10.2//bean2.Car.java package com.sxs.spring.bean;/*** author 孙显圣* version 1.0*/ public class Car {private Integer id;private String name;private Double price;public Car() {}public Car(Integer id, String name, Double price) {this.id id;this.name name;this.price price;}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 Double getPrice() {return price;}public void setPrice(Double price) {this.price price;}Overridepublic String toString() {return Car{ id id , name name \ , price price };} } 3.SpringBeanTest.java //得到car对象Testpublic void getCarObject() {ApplicationContext ioc new ClassPathXmlApplicationContext(beans.xml);Car car ioc.getBean(car, Car.class);System.out.println(car);}4.结果
http://www.pierceye.com/news/823441/

相关文章:

  • 长宁区科技网站建设科技类网站怎么做
  • 物流企业的网站模板wordpress海淘
  • 青岛做外贸网站的公司简介重庆关键词优化平台
  • 黄岛外贸网站建设很多网站没排名了
  • 广州做网站优化费用网站建设和制作
  • 修改网站域名网站收录低的原因
  • 网站登录页面模板下载做网站背景
  • 温州网站推广驭明电脑网站模版
  • 高端定制网站开发需要多少钱秦皇岛优化网站排名
  • 有网站源码怎么搭建网站南京网站制作设计公司
  • 做网站学什么专业建个什么网站赚钱
  • 衡阳手机网站设计世界上有几个空间站
  • 推荐个做淘宝主图视频的网站苍南最好的网站建设公司
  • 山东中迅网站建设wordpress固定链接翻页404
  • 网站 改版农业网站建设方案 ppt
  • 网关高性能 网站建设设计制作长方体形状的包装纸盒视频
  • 如何做游戏推广网站廊坊百度推广公司地址
  • 国产做爰网站wordpress wrapper
  • 专业论坛网站开发开发长沙网站建设+个人
  • 河南便宜网站建设费用wordpress 记录访问ip
  • 汽车网站建设代理加盟深圳网络制作公司
  • 国外的旅游网站做的如何织梦网站根目录在哪里
  • 网站建设建站在线建站专业网站建设机构
  • 西安市城乡建设网官方网站衡水移动网站建设报价
  • 禅城区企业网站建设微信公众号网页版入口
  • 网站开发概述多城市二手车网站源码
  • 网站建设的内容策略本人做静态网站开发
  • 网站建设到运营赚钱网站主体负责人邮箱
  • 国外有在线做设计方案的网站吗网站地址免费
  • 做谷歌网站使用什么统计代码吗公司流程建设的意义