实体类
package POJO;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class User {
private String name;
private Address address;
private String[] books;
private List<String> hobbys;
private Map<String,String> crad;
private Set<String> games;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public String[] getBooks() {
return books;
}
public void setBooks(String[] books) {
this.books = books;
}
public List<String> getHobbys() {
return hobbys;
}
public void setHobbys(List<String> hobbys) {
this.hobbys = hobbys;
}
public Map<String, String> getCrad() {
return crad;
}
public void setCrad(Map<String, String> crad) {
this.crad = crad;
}
public Set<String> getGames() {
return games;
}
public void setGames(Set<String> games) {
this.games = games;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", address=" + address +
", books=" + Arrays.toString(books) +
", hobbys=" + hobbys +
", crad=" + crad +
", games=" + games +
'}';
}
}
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="address" class="POJO.Address">
<property name="address" value="add"></property>
</bean>
<bean id="id01" class="POJO.User">
<!--普通值注入-->
<property name="name" value="guan"></property>
<!--Bean注入-->
<property name="address" ref="address"></property>
<!--数组注入-->
<property name="books">
<array>
<value>英语</value>
<value>语文</value>
<value>数学</value>
</array>
</property>
<!--List注入-->
<property name="hobbys">
<list>
<value>睡觉</value>
<value>打篮球</value>
<value>旅游</value>
</list>
</property>
<!--Map注入-->
<property name="crad">
<map>
<entry key="俺男人" value="真的"></entry>
<entry key="俺女人" value="假的"></entry>
</map>
</property>
<!--Set注入-->
<property name="games">
<set>
<value>LOL</value>
<value>COC</value>
<value>BOB</value>
</set>
</property>
</bean>
</beans>