1、bean里面
package com.yuanfeng.bean;/** * Created by yuanfeng on 2019/7/11 14:15 */ import java.io.Serializable; import java.util.*; /** *@ClassName Person *@Description T0D0 *@Author yuanfeng *@Date 2019/7/11 14:15 *@Version 1.0 **/ public class Person implements Serializable { private String[] hobby; private List<String> names;//list private Set<String> colors;//set private Map<String,String> map;//map private Properties properties; public List<String> getNames() { return names; } public void setNames(List<String> names) { this.names = names; } public Set<String> getColors() { return colors; } public void setColors(Set<String> colors) { this.colors = colors; } public Map<String, String> getMap() { return map; } public void setMap(Map<String, String> map) { this.map = map; } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } public void show(){ System.out.println("数组"+ Arrays.toString(hobby)); System.out.println("list"+ names); System.out.println("set"+ colors); System.out.println("map"+ map); System.out.println("properties"+ properties); } public String[] getHobby() { return hobby; } public void setHobby(String[] hobby) { this.hobby = hobby; } }
2、applicationContext.xml
<?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 id="p" class="com.yuanfeng.bean.Person"> <!--测试数组--> <property name="hobby"> <list> <value>学画画</value> <value>弹吉他</value> <value>学游泳</value> </list> </property> <!--测试list集合--> <property name="names"> <list> <value>中国</value> <value>小日本</value> <value>美国</value> </list> </property> <!--测试set集合--> <property name="colors"> <set> <value>笑傲江湖</value> <value>招摇</value> <value>村上村塾</value> </set> </property> <!--测试map集合--> <property name="map"> <map> <entry key="zjl"><value>周杰伦</value></entry> <entry key="cyx"><value>陈奕迅</value></entry> <entry key="zxy"><value>张学友</value></entry> </map> </property> <!--测试properties--> <property name="properties"> <map> <entry key="username"><value>zhoujielun</value></entry> <entry key="password"><value>1234</value></entry> <entry key="driverClass"><value>com.mysql.jdbc.Driver</value></entry> </map> </property> </bean> </beans>