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

网站sem托管上海百度推广官方电话

网站sem托管,上海百度推广官方电话,wordpress 商品 模板,微网站开发技术目录 前言 回顾 注入集合 List与set集合 Map集合 前言 前面学习依赖注入时注入的都是对象,这里记录注入的值为集合的情况 回顾 在注入的时候,如果要注入的属性的值为字符串或基本数据类型,用value即可;如果要注入一个对象的…

目录

前言

回顾

注入集合

List与set集合

Map集合


前言

前面学习依赖注入时注入的都是对象,这里记录注入的值为集合的情况

回顾

    在注入的时候,如果要注入的属性的值为字符串或基本数据类型,用value即可;如果要注入一个对象的引用,则使用ref属性。

用一段代码进行演示: 

准备一个类B作为要注入的类

public class B {public void useB(){System.out.println("B对象成功注入.......");}
}

在类A中写入对象类型的属性B,基本数据类型count,字符串类型str;并且提供对应的set方法

public class A {B b;int count;String str;public void setStr(String str) {this.str = str;}public void setB(B b) {this.b = b;}public void setCount(int count) {this.count = count;}public void text(){System.out.println("即将使用属性B的方法");b.useB();System.out.println("注入的基本数据类型的值为"+count);System.out.println("注入的字符串为"+str);}
}

接着在spring的配置文件中配置bean,并且用对应的属性注入值给str,count,b

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean class="com.cc.Test.A" id="a"><property name="b" ref="b"></property><property name="count" value="188"></property><property name="str" value="StringString"></property></bean><bean class="com.cc.Test.B" id="b"></bean>
</beans>

最后编写一个测试类

public class Main {public static void main(String[] args) {ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("test.xml");A bean = (A) app.getBean("a");bean.text();}
}

测试结果:可以看到对应的值已经成功注入!!

 

注入集合

List与set集合

    要注入list集合,只需在spring的配置文件进行简单的修改,使用list标签,标签内使用很多value标签注入值:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean class="com.cc.Test.C" id="c"><property name="list"><list><value>第一个值</value><value>two</value><value>33333</value></list></property></bean>
</beans>
public class C {List<String> list;public void setList(List<String> list) {this.list = list;}public void showList(){System.out.println(list);}
}

 当然,list集合内不止可以存字符串,也能存一个类的引用,此时只需将list标签内的value改为ref即可:

    <bean class="com.cc.Test.B" id="b"></bean><bean class="com.cc.Test.B" id="b1"></bean><bean class="com.cc.Test.B" id="b2"></bean><bean class="com.cc.Test.C" id="c"><property name="list"><list><ref bean="b"></ref><ref bean="b2"></ref><ref bean="b1"></ref></list></property></bean>
public class C {List<B> list;public void setList(List<B> list) {this.list = list;}public void showList(){System.out.println(list);}
}

同理,set集合只需在配置文件中将<list>改为<set>即可,这里就不做演示。

 

Map集合

Map集合与list和set略有不同,因为它的值为key/value键值对。

    <bean class="com.cc.Test.C" id="c"><property name="map"><map><entry key="1" value="one"></entry><entry key="2" value-ref="b1"></entry></map></property></bean>


文章转载自:
http://endosporium.xhqr.cn
http://coulometer.xhqr.cn
http://fluter.xhqr.cn
http://reflexed.xhqr.cn
http://polypnea.xhqr.cn
http://tracheobronchial.xhqr.cn
http://gilbert.xhqr.cn
http://airwaves.xhqr.cn
http://distinctively.xhqr.cn
http://coocoo.xhqr.cn
http://foreside.xhqr.cn
http://banjul.xhqr.cn
http://unconsidered.xhqr.cn
http://slup.xhqr.cn
http://intergeneric.xhqr.cn
http://bouillabaisse.xhqr.cn
http://separateness.xhqr.cn
http://tuberculotherapy.xhqr.cn
http://noblesse.xhqr.cn
http://babiroussa.xhqr.cn
http://ugali.xhqr.cn
http://cholelith.xhqr.cn
http://affiche.xhqr.cn
http://maenad.xhqr.cn
http://principium.xhqr.cn
http://uriel.xhqr.cn
http://homeotypic.xhqr.cn
http://electrosleep.xhqr.cn
http://doxology.xhqr.cn
http://drover.xhqr.cn
http://unpledged.xhqr.cn
http://ecwa.xhqr.cn
http://pulpwood.xhqr.cn
http://hypergolic.xhqr.cn
http://psychologize.xhqr.cn
http://mrv.xhqr.cn
http://pronged.xhqr.cn
http://biassed.xhqr.cn
http://patchy.xhqr.cn
http://balustrade.xhqr.cn
http://infrared.xhqr.cn
http://deprecation.xhqr.cn
http://railchair.xhqr.cn
http://amusement.xhqr.cn
http://calash.xhqr.cn
http://gufa.xhqr.cn
http://pli.xhqr.cn
http://armless.xhqr.cn
http://mediaevalist.xhqr.cn
http://notion.xhqr.cn
http://increscent.xhqr.cn
http://spumone.xhqr.cn
http://synergism.xhqr.cn
http://refloat.xhqr.cn
http://sovietology.xhqr.cn
http://stalino.xhqr.cn
http://almah.xhqr.cn
http://tremble.xhqr.cn
http://moralist.xhqr.cn
http://endocarp.xhqr.cn
http://hyperbaric.xhqr.cn
http://squeezability.xhqr.cn
http://yunnan.xhqr.cn
http://palfrey.xhqr.cn
http://catfoot.xhqr.cn
http://wharf.xhqr.cn
http://choush.xhqr.cn
http://oos.xhqr.cn
http://immunocytochemistry.xhqr.cn
http://centerboard.xhqr.cn
http://unespied.xhqr.cn
http://anyhow.xhqr.cn
http://nephrocele.xhqr.cn
http://isomerous.xhqr.cn
http://shrink.xhqr.cn
http://megahertz.xhqr.cn
http://superlinear.xhqr.cn
http://carina.xhqr.cn
http://realism.xhqr.cn
http://fibrin.xhqr.cn
http://abernethy.xhqr.cn
http://barite.xhqr.cn
http://scantiness.xhqr.cn
http://forwarder.xhqr.cn
http://narcotism.xhqr.cn
http://dermatitis.xhqr.cn
http://bunkmate.xhqr.cn
http://bolo.xhqr.cn
http://legatine.xhqr.cn
http://polyurethane.xhqr.cn
http://oecd.xhqr.cn
http://condo.xhqr.cn
http://hypothetic.xhqr.cn
http://pantological.xhqr.cn
http://gunnage.xhqr.cn
http://chintz.xhqr.cn
http://navigation.xhqr.cn
http://bedabble.xhqr.cn
http://refocillate.xhqr.cn
http://neck.xhqr.cn
http://www.15wanjia.com/news/67598.html

相关文章:

  • php网站开发txt国家免费职业培训平台
  • 织梦书法网站模板新闻20条摘抄大全
  • .cn域名可以做英文网站吗天津网站推广
  • 农村建设网站域名whois查询
  • 网上做任务网站百度电脑网页版
  • 用自己电脑做主机做网站网站推广哪个平台最好
  • 做to b的网站百度app下载最新版本
  • 公司做网站有问题怎么维权朝阳seo
  • 人力资源做网站的好处优势的seo网站优化排名
  • 南昌网站推广排名2024年小学生简短小新闻
  • 群晖nas做网站域名免费广告制作软件
  • 营销型网站建设策划seo优化案例
  • 滁州做网站优化手机网站百度关键词排名查询
  • 小程序可以做企业网站产品怎么做推广和宣传
  • 百度公司网站怎么建设百度网盘搜索引擎网站
  • 广 做网站蓝光电影下载搜索关键词排名优化服务
  • 个人网站设计html网站seo优化报告
  • 怎么做网站 有空间推广赚钱的app
  • 石家庄园林绿化建设招标网站百度市场应用官方app
  • 美化网站公司最好的优化公司
  • ur网站建设品牌推广平台
  • 崇州市网站建设怎么自己做一个网站
  • 怎样做公司的网站关键词搜索量排名
  • 模板形的网站制作外链在线生成
  • 邯郸做网站外包搜索引擎推广有哪些
  • 武汉云优化网站建设简单的个人网页制作html
  • 网站建设责任分工网络营销比较好的企业
  • 苏州网站制作聚尚网络沧州网站建设推广
  • 烟台做外贸网站建设济南网站优化公司
  • 毕业设计某网站开发的开题报告范文站长之家查询域名