Spring为list集合和map集合类型赋值
1.通过List标签在property标签中直接进行赋值
<property name="students">
<list>
<ref bean="studentOne"></ref>
<ref bean="studentTwo"></ref>
</list>
</property>
2.通过配置一个list集合类型的bean,需要使用util的约束(直接写,可以自动导入)
然后再通过id引用该list集合
<util:list id="studentList">
<ref bean="studentThree"></ref>
<ref bean="studentFour"></ref>
<ref bean="studentFive"></ref>
</util:list>
<property name="students" ref="studentList"></property>
1.通过map标签在property标签中直接进行赋值
<property name="teacherMap">
<map>
<entry key="10086" value-ref="teacherOne"></entry>
<entry key="10010" value-ref="teacherTwo"></entry>
</map>
</property>
2.通过配置一个map集合类型的bean,需要使用util的约束(直接写,可以自动导入)
然后再通过id引用该map集合
<util:map id="teacherMap">
<entry key="10086" value-ref="teacherOne"></entry>
<entry key="10010" value-ref="teacherTwo"></entry>
</util:map>
<property name="teacherMap" ref="teacherMap"></property>
在map集合中,如果要用到的是字面量赋值,就使用key or value
如果要通过类赋值 就使用key-ref or value-ref

浙公网安备 33010602011771号