bean 标签
id 属性,唯一标识
class 属性,类的全类名,反射,无参数构造函数
property 标签
name 属性,类里面的属性
value 属性,赋值
赋值:
bean引用:一个对象里面有个属性是另外一个对象
ref 标签,有两种写法,在property标签里面使用属性 ref;在property标签之间使用ref单标签
内部bean
bean标签作为property子标签
bean 里面的集合
<!-- list -->
<bean id="p3_cars1" class="com.curtis.spring.Person3">
<property name="name" value="Curtis"></property>
<property name="age" value="26"></property>
<property name="cars">
<list>
<ref bean="car1" />
<bean class="com.curtis.spring.Cars">
<property name="brand" value="mas"></property>
<property name="price" value="500000"></property>
<property name="speed" value="260"></property>
</bean>
</list>
</property>
</bean>
bean 里面的map
<bean id="p4_cars1" class="com.curtis.spring.Person4">
<property name="name" value="Curtis"></property>
<property name="age" value="26"></property>
<property name="carsMap">
<map>
<entry key="A" value-ref="car1"></entry>
<entry key="B" value-ref="car2"></entry>
</map>
</property>
</bean>
bean 之间的继承,依赖关系
外部配置文件
<!--
命名空间:http://www.springframework.org/schema/context
db.properties 文件存放路径要在classpath 也就是类路径下
-->
<context:property-placeholder location="classpath:db.properties"/>
在xml 文件里面使用配置里面的信息用:${}
<!-- 代码的重复利用 -->
http://www.springframework.org/schema/util
<util:list id="cars">
<ref bean="car1" />
<ref bean="car2" />
</util:list>
命名空间p
http://www.springframework.org/schema/p
<bean id="p3_cars2" class="com.curtis.spring.Person3" p:name="Curtis" p:age="26" p:cars-ref="cars"></bean>
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123