兩個類以下
//personspring
public class Person { private String name; private int age; private Car car; }
//car類code
public class Car { private String name; private String address; private double price; }
以下是在person類中給car類中的屬性設值,稱之爲級聯屬性賦值class
<!-- 配置bean --> <bean id="car" class="com.test.spring.beans.Car"> <property name="name" value="audi"></property> <property name="address" value="shanghai"></property> <!-- <property name="price" value="200"></property> --> </bean> <!-- 引用bean --> <bean id="person" class="com.test.spring.beans.Person"> <property name="name" value="zhangsan"></property> <property name="age" value="30"></property> <!-- 使用property的ref屬性創建bean之間的引用關係 --> <property name="car" ref="car"></property> <!-- 爲級聯屬性賦值,首先必須引用級聯屬性的類 --> <property name="car.price" value="35"></property> </bean>