public class ArrayTest {
private String[] names;
/** * @param args */ public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("test/array/array-context.xml"); ArrayTest at = (ArrayTest)ctx.getBean("at"); for(int i = 0; i < at.getNames().length; i++){ String s = at.getNames()[i]; System.out.println("s=" + s); } }public String[] getNames() {
return names; }public void setNames(String[] names) {
this.names = names; }}
使用list
<beans>
<bean id="at" class="test.array.ArrayTest"> <property name="names"> <list> <value>aaa</value> <value>bbb</value> </list> </property> </bean></beans>
或者逗号分开
<beans>
<bean id="at" class="test.array.ArrayTest"> <property name="names"> <value>aaa,bbb</value> </property> </bean></beans>