实体类如下:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
private int age;
private String name;
private Phone phone;
private List<String> list;
private List<Phone> phones;
private Set<String> set;
private Map<String, Phone> map;
private int[] arr;
private Properties properties;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Phone {
private double price;
private String name;
private String password;
private String path;
}
配置如下:
<?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 class="com.leon.domain.Phone" id="phone">
<property name="price" value="3999"></property>
<property name="name" value="黑米"></property>
<property name="password" value="123"></property>
<property name="path" value="qqqq"></property>
</bean>
<bean class="com.leon.domain.User" id="user">
<property name="age" value="10"></property>
<property name="name" value="大队长"></property>
<property name="phone" ref="phone"></property>
<property name="list">
<list>
<value>三更</value>
<value>西施</value>
</list>
</property>
<property name="phones">
<list>
<ref bean="phone"></ref>
</list>
</property>
<property name="set">
<set>
<value>setEle1</value>
<value>setEle2</value>
</set>
</property>
<property name="map">
<map>
<entry key="k1" value-ref="phone"></entry>
<entry key="k2" value-ref="phone"></entry>
</map>
</property>
<property name="arr">
<array>
<value>10</value>
<value>11</value>
</array>
</property>
<property name="properties">
<props>
<prop key="k1">v1</prop>
<prop key="k2">v2</prop>
</props>
</property>
</bean>
</beans>