<?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="address" class="com.kuang.pojo.Address"></bean> <bean id="student" class="com.kuang.pojo.Student"> <!--普通注入--> <property name="name" value="郭俊"/> <!-- Bean注入--> <property name="address" ref="address"/> <!-- 数组注入--> <property name="books"> <array> <value>红楼梦</value> <value>西游记</value> <value>水浒传</value> <value>三国演义</value> </array> </property> <!-- List注入--> <property name="hobbys"> <list> <value>听歌</value> <value>敲代码</value> <value>看电影</value> </list> </property> <!-- Map注入--> <property name="card"> <map> <entry key="身份证" value="1517233142"></entry> <entry key="银行卡" value="44444444"></entry> </map> </property> <!-- Set注入--> <property name="games"> <set> <value>LOL</value> <value>COC</value> <value>BOB</value> </set> </property> <!-- null注入--> <property name="wife"> <null></null> </property> <!-- Property注入--> <property name="info"> <props> <prop key="学号">204804112</prop> <prop key="性别">男</prop> <prop key="username">root</prop> <prop key="password">123456</prop> </props> </property> </bean> </beans>
结果
Student{name='郭俊', address=Address{address='null'},
books=[红楼梦, 西游记, 水浒传, 三国演义],
hobbys=[听歌, 敲代码, 看电影],
card={身份证=1517233142, 银行卡=44444444},
games=[LOL, COC, BOB], wife='null',
info={password=123456, 学号=204804112, username=root, 性别=男}}