1.set注入

spring通过调用类的set方法实现属性赋值

<bean id="student" class="ccutchi.cla.impl.StudentImpl">

   <property name="name" value="guoyuan" />

   <property name="age" value="17" />

   <property name="school" ref="school" />

</bean>



<bean id="school" class="ccutchi.cla.impl.SchoolImpl">

   <property name="name" value="长春工业大学人文信息学院"/>

   <property name="adress" value="长春" />

</bean>

2.构造注入

sprint通过调用类的有参构造函数实现属性赋值

<bean id = "mySchool" class="ccutchi.cla.impl.SchoolImpl">

  <constructor-arg index="0" value="长春工业大学人文信息学院"/>

  <constructor-arg index="1" value = "长春1" />

</bean>

 

<bean id = "mySchool1" class="ccutchi.cla.impl.SchoolImpl">

  <constructor-arg value="长春工业大学人文信息学院" />

  <constructor-arg value="长春2" />

</bean>

 

<bean id = "mySchool2" class="ccutchi.cla.impl.SchoolImpl">

  <constructor-arg name="name" value="长春工业大学人文信息学院" />

  <constructor-arg name="adress" value="长春3" />

</bean>
文章作者: 郭远
本文链接:
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 郭远的博客空间
Spring Spring
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝