本人刚刚入门SSH,今天对自己所学进行一些小小的总结
<bean id="axe1" class="com.ctgu.SteelAxe"></bean>
<bean id="axe2" class="com.ctgu.StoneAxe"></bean>
<bean id="worker" class="com.ctgu.Worker">
<!--控制器将调用set()方法 将axe1作为传入的参数 -->
<!-- 这里的name是决定Worker类中对应属性的参数 -->
<!-- ref则指向前面注册的id为“axe1”的bean -->
<property name="axe" ref="axe1"></property>
<property name="name" value="工人"></property>
</bean>
<bean id="author" class="com.ctgu.Author">
<property name="axe" ref="axe2"></property>
<property name="name" value="作家" ></property>
</bean>
配置bean的property进行参数注入,而在对应的类中必须要有set(),get()方法才能进行参数注入。
name指bean标签中class中的参数,而ref 则指当前xml中配置的bean的id 然后将对应的bean作为参数传入class。
value 则可以对参数进行简单的赋值