Spring框架总结三---集合属性bean共享集合

一.Teacher类中包含的属性

	private Integer tid;
	
	private String tname;
	
	private List<String> courses;     //表示该老师教授课程名
	
	private List<Student> students;   //表示该老师所教授的学生
	
	private Map<String,String> day_works;  //表示每天的任务
	
	private Map<String,Student> day_students;  //表示每天辅导的学生
	
	private Map<Student,Student> student_students;  //表示结对学习

二.集合框架

1.List结构字段 List<>

i.value方式赋值

<bean id="teacher2" class="com.school.Teacher">
		<property name="tid" value="20150002"></property>
		<property name="tname" value="Zhou Jianping"></property>
		<property name="courses">
			<list>
				<value>English</value>
				<value>Chinese</value>
				<value>Math</value>
			</list>
		</property>
	</bean>

ii.ref引用赋值

<bean id="teacher3" class="com.school.Teacher">
		<property name="tid" value="20150003"></property>
		<property name="tname" value="Zhu Hanqin"></property>
		<property name="students">
			<list>
				<ref bean="student2" />
				<ref bean="student3" />
				<ref bean="student4" />
			</list>
		</property>
	</bean>

2.Map结构字段 Map<>

Map<键,值>:当键和值为普通字面量时用value包裹,非字面量可以采用ref引用,甚至可能采取嵌套的方式

<map>
    <entry>
        <key>
            <value></value>
        </key>
        <value></value>
    </entry>
</map>
<map>
	<entry>
		<key>
			<ref bean="student10" />
		</key>
		<ref bean="student12" />
	</entry>
</map>

i.<String,String>类型(此处用String代表一般字面量,可根据实际需要换成其他类型)

<bean id="teacher4" class="com.school.Teacher">
		<property name="tid" value="20150004"></property>
		<property name="tname" value="Zhao Yu"></property>
		<property name="day_works">
			<map>
				<entry>
					<key>
						<value>Monday</value>
					</key>
					<value>安排本周教学计划</value>
				</entry>
				<entry>
					<key>
						<value>Tuesday</value>
					</key>
					<value>家访</value>
				</entry>
			</map>
		</property>
	</bean>

ii.<String,Object>类型

<bean id="teacher5" class="com.school.Teacher">
		<property name="tid" value="20150005"></property>
		<property name="tname" value="Feng Zhigang"></property>
		<property name="day_students">
			<map>
				<entry>
					<key>
						<value>Monday</value>
					</key>
					<ref bean="student12" />
				</entry>
				<entry>
					<key>
						<value>Tuesday</value>
					</key>
					<ref bean="student11" />
				</entry>
			</map>
		</property>
	</bean>

iii.<Object,Object>

<bean id="teacher6" class="com.school.Teacher">
		<property name="tid" value="20150006"></property>
		<property name="tname" value="Zhang Zhanni"></property>
		<property name="student_students">
			<map>
				<entry>
					<key>
						<ref bean="student10" />
					</key>
					<ref bean="student12" />
				</entry>
				<entry>
					<key>
						<ref bean="student9" />
					</key>
					<ref bean="student11" />
				</entry>
			</map>
		</property>
	</bean>

3.bean共享集合对象

<util:list id="courses">
		<value>English</value>
		<value>Chinese</value>
		<value>Math</value>
</util:list>
<util:map id="map_day_student">
	<entry>
		<key>
			<value>Monday</value>
		</key>
		<ref bean="student5" />
	</entry>
	<entry>
		<key>
			<value>Tuesday</value>
		</key>
		<ref bean="student6" />
	</entry>
</util:map>
	<bean id="teacher7" class="com.school.Teacher">
		<property name="tid" value="20150007"></property>
		<property name="tname" value="Han Jian"></property>
		<property name="courses">
			<ref bean="courses" />
		</property>
		<property name="day_students">
			<ref bean="map_day_student" />
		</property>
	</bean>
	<bean id="teacher8" class="com.school.Teacher">
		<property name="tid" value="20150008"></property>
		<property name="tname" value="Liu Guichao"></property>
		<property name="courses">
			<ref bean="courses" />
		</property>
		<property name="day_students">
			<ref bean="map_day_student" />
		</property>
	</bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值