package
com.open.bean;
import
java.util.List;
import
java.util.Map;
import
java.util.Properties;
public
class
BeanSet
{
private
String[] str1;
private
String[] str2;
private
List lst;
private
Map map;
private
Properties props;
private
ChildBean[] child;
//
省略set,get方法
}
package
com.open.bean;
public
class
ChildBean
{}
配置文件
<beans> <bean id="bs" class="com.open.bean.BeanSet"> <property name="str1"> <list> <value>value1</value> <value>value2</value> </list> </property> <property name="str2"> <value>value3,value4</value> </property> <property name="lst"> <list> <value>value5</value> <ref bean="cc1"/> </list> </property> <property name="map"> <map> <entry key="key1"> <value>xxx</value> </entry> <entry key="key2"> <ref bean="cc1"/> </entry> </map> </property> <property name="props"> <props> <prop key="key1">xxx</prop> <prop key="key2">yyy</prop> </props> </property> <property name="child"> <list> <ref bean="cc1"/> <ref bean="cc2"/> </list> </property> </bean> <bean id="cc1" class="com.open.bean.ChildBean"/> <bean id="cc2" class="com.open.bean.ChildBean"/> </beans> 测试代码
package com.open.bean; import java.util.List; import java.util.Map; import java.util.Properties; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test1 { public static void main(String[] args) { ClassPathXmlApplicationContext cx= new ClassPathXmlApplicationContext("bean.xml"); BeanSet bs=(BeanSet)cx.getBean("bs"); String[] str1=bs.getStr1(); String[] str2=bs.getStr1(); List lst=bs.getLst(); Map map=bs.getMap(); Properties props=bs.getProps(); ChildBean[] cb=bs.getChild(); System.out.println("str1="+"["+str1[0]+","+str1[1]+"]"); System.out.println("str2="+"["+str2[0]+","+str2[1]+"]"); System.out.println("lst="+lst); System.out.println("map="+map); System.out.println("props="+props); System.out.println("cb="+"["+cb[0]+","+cb[1]+"]"); } } 输出结果
str1=[value1,value2] str2=[value1,value2] lst=[value5, com.open.bean.ChildBean@1df073d] map={key1=xxx, key2=com.open.bean.ChildBean@1df073d} props={key2=yyy, key1=xxx} cb=[com.open.bean.ChildBean@1df073d,com.open.bean.ChildBean@1546e25]
|
|
公告
常用链接
留言簿(4)
随笔分类
相册
Blog
论坛
积分与排名
最新评论
|
|