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

沈阳专业制作网站网站子站怎么做、

沈阳专业制作网站,网站子站怎么做、,网页制作平台排行榜,东莞网站页设计制作目录 IOC操作Bean管理XML方式#xff08;xml自动装配#xff09; 一.演示自动装配过程 #xff08;1#xff09;根据 属性名称 装配 步骤一#xff1a; 步骤二#xff1a; 步骤三#xff1a; #xff08;2#xff09;根据 属性类型 装配 #xff08;2.1#…目录 IOC操作Bean管理XML方式xml自动装配 一.演示自动装配过程 1根据 属性名称 装配 步骤一 步骤二 步骤三  2根据 属性类型 装配 2.1根据 类型 自动装配产生的问题 解决方法 IOC操作Bean管理XML方式xml自动装配 手动装配 之前写的代码中可以往一个类中注入属性做法就是在xml配置文件中通过property标签中的name属性包括value属性值向类中设置值这种方式叫做 手动装配 自动装配 直接根据装配规则【属性名称或者属性类型】不需要明确指定是什么名称或者什么类型Spring自动将匹配的属性值进行注入这种方式叫做 自动装配 一.演示自动装配过程 1根据 属性名称 装配 步骤一 创建一个autowire包写入两个类员工类Employee类部门类Department类 结构如下 Employee类代码如下 package com.lbj.spring5.autowire;public class Employee {//写入部门对象//效果 在Employee中注入Department对象private Department department;public void setDepartment(Department department) {this.department department;}//加入toString方法方便输出Overridepublic String toString() {return Employee{ department department };}//加入测试方法方便测试public void test(){System.out.println(department);}}Department类 package com.lbj.spring5.autowire;public class Department { } 步骤二 新建一个bean5.xml配置文件 分别在配置文件中将两个类的对象进行创建 然后根据属性名称自动注入 代码如下 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:utilhttp://www.springframework.org/schema/utilxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd!--实现自动装配bean 标签属性 autowire配置自动装配autowire属性常用两个值byName 根据属性名称注入注入的id值和类属性名称一样byType 根据属性类型注入 --bean idemployee classcom.lbj.spring5.autowire.Employee autowirebyName!--property namedepartment refdepartment/property--/beanbean iddepartment classcom.lbj.spring5.autowire.Department/bean/beans 测试类 package com.lbj.spring5.testdemo;import com.lbj.spring5.autowire.Employee; import com.lbj.spring5.bean.Orders; import com.lbj.spring5.collectiontype.Book; import com.lbj.spring5.collectiontype.Course; import com.lbj.spring5.collectiontype.Student; import com.lbj.spring5.factorybean.Mybean; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestSpring5Demo1 {Testpublic void tsetBean2(){ApplicationContext contextnew ClassPathXmlApplicationContext(bean5.xml);Employee employeecontext.getBean(employee, Employee.class);System.out.println(employee);} }步骤三  测试结果 2根据 属性类型 装配 bean5.xml去Employee类中找到Department类的类型去装配 bean5.xml配置如下 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:utilhttp://www.springframework.org/schema/utilxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd!--实现自动装配bean 标签属性 autowire配置自动装配autowire属性常用两个值byName 根据属性名称注入注入的id值和类属性名称一样byType 根据属性类型注入--bean idemployee classcom.lbj.spring5.autowire.Employee autowirebyType!--property namedepartment refdepartment/property--/beanbean iddepartment classcom.lbj.spring5.autowire.Department/bean/beans 测试结果  2.1根据 类型 自动装配产生的问题 根据 类型 自动装配时相同类型的bean对象不能定义多个否则类型识别不出来是哪个bean注入 如下所示  解决方法 1.使用 注解 2.使用 属性名称 装配
http://www.yutouwan.com/news/446285/

相关文章:

  • 找人做淘宝网站需要多少钱企业概况的内容
  • 泰安网站建设作用上海哪家网站建设好
  • 购物网站开发的必要性微信公众号登录平台登录官网
  • 网站型销售怎么做中国工商银行app下载
  • 微信公众号推广方法有哪些网站优化排名分享隐迅推
  • 网站做备案需要多久百度链接地址
  • 关于做网站的毕业设计emlog怎么做视频网站
  • 网站悬浮广告素材深圳交易服务中心官网
  • 报喜鸟集团有限公司网页制作seo运营是什么
  • 社区子网站群建设wordpress 模拟word
  • 蜀都网站建设舜王asp.net学校网站整站系统源码
  • 黄页88网站关键词怎么做怎么做网站需要多少钱
  • 盈科互动网站建设制作公司杭州竞彩网站开发
  • 中国建设银行网站无法访问东营网红桥
  • 哈尔滨php网站开发公司郑州企业网站优化排名
  • 百度收录网站怎么做制作网站和制作网页的分别
  • 做网站最简单的方法wordpress微信分享图片不显示
  • 网站备案授权书怎么填河北建设厅网站开通账号
  • 河南建设教育协会网站网站设计培训成都哪家好
  • 做司考题的网站南宁网络推广方案
  • 网站怎么解析域名小说网站设计模板
  • 泰安高新区建设局网站网页美工设计师
  • 磁盘阵列做网站天长哪个广告公司做网站
  • 网站文章排版的重要性wordpress 腾讯验证码
  • 松江网站开发培训班安徽seo优化规则
  • 建设医院官方网站网站维护中一般要多长时间
  • 网站建设包含的内容win10 做网站服务器吗
  • 网站内容运营h5商城和小程序商城的区别
  • 河北建设行业信息网站html网页表格代码
  • 网页建设网站代码网站蜘蛛来访纪录