admin 管理员组

文章数量: 888358

跟杨春娟学Spring笔记:集合装配

跟杨春娟学Spring笔记:集合装配

完成:第一遍

1.常见集合元素有哪些?

集合元素 :
用途:装配list类型的值,允许重复

集合元素 :
用途:装配set类型的值,不允许重复

集合元素 :
用途:装配map类型的值,名称和值可以是任意类型

集合元素 :
用途: 装配properties类型的值,名称和值必须都是 String类型

集合元素 :
用途: 装配数组的值

com.adbycool.ioc.IOCCollections

package com.adbycool.ioc;import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;public class IOCCollections {private List <String> listColl;private Set <String> setColl;private String[] arrayColl;private Map<String,String> mapColl;private Properties  proColl;public List<String> getListColl() {return listColl;}public void setListColl(List<String> listColl) {this.listColl = listColl;}public Set<String> getSetColl() {return setColl;}public void setSetColl(Set<String> setColl) {this.setColl = setColl;}public String[] getArrayColl() {return arrayColl;}public void setArrayColl(String[] arrayColl) {this.arrayColl = arrayColl;}public Map<String, String> getMapColl() {return mapColl;}public void setMapColl(Map<String, String> mapColl) {this.mapColl = mapColl;}public Properties getProColl() {return proColl;}public void setProColl(Properties proColl) {this.proColl = proColl;}@Overridepublic String toString() {return "IOCCollections [listColl=" + listColl + ", setColl=" + setColl + ", arrayColl="+ Arrays.toString(arrayColl) + ", mapColl=" + mapColl + ", proColl=" + proColl + "]";}}

com.adbycool.ioc.Test

package com.adbycool.ioc;import static org.junit.jupiter.api.Assertions.*;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;class Test {@org.junit.jupiter.api.Testvoid test() {ApplicationContext context =  new ClassPathXmlApplicationContext("applicationContext.xml");IOCCollections iocCollections = context.getBean("iOCCollections",IOCCollections.class);System.out.println(iocCollections);}}

applicationContext

<?xml version="1.0" encoding="UTF-8"?><beans xmlns=""xmlns:xsi=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans-4.3.xsd"><bean  id="iOCCollections" class="com.adbycool.ioc.IOCCollections"><!--setter注入方式  --><property name="listColl"><list><value>China</value><value>Japan</value><value>America</value></list>     </property><property name="setColl"><set><value>Beijing</value><value>Shanghai</value><value>Shenzhen</value></set>     </property><property name="arrayColl"><array><value>Qingdao</value><value>Dalian</value>   </array>           </property><property name="mapColl"><map><entry ><key><value>1001</value></key><value>ZhangSan</value></entry><entry key="1002" value="Jack"></entry>      </map>       </property><property name="proColl"><props><prop key="username">root</prop><prop key="password">123456</prop></props>  </property></bean></beans>

本文标签: 跟杨春娟学Spring笔记集合装配