Spring可以在ApplicationContext.xml中使用方式給予多個資料,要開始Run專案我轉職後第一個挑戰,每這幾天一直有想找是否有可以從網路系統工程切入程式的工作,新環境摸不著北感覺好無助~希望能加油下去
XML
```<!-- 測試如何配置集合屬性 -->
<bean id="person3" class="com.spring.collection.Person">
<property name="name" value="Mike"></property>
<property name="age" value="23"></property>
<property name="cars">
<list>
<ref bean="car"/>
<ref bean="car2"/>
</list>
</property>
</bean>
```
Main.java
```public class Main {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
Person person = (Person) ctx.getBean("person3");
System.out.println(person);
}
}```
Person.java
```public class Person {
private String name;
private int age;
private List<Car> cars;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public List<Car> getCars() {
return cars;
}
public void setCars(List<Car> cars) {
this.cars = cars;
}
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + ", cars=" + cars + "]";
}
}
}```