1. Bean
package com.cloud.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
private String name;
private int age;
private double balance;
private char firstLetter;
private boolean married;
private List<String> hobby;
private Set<String> address;
private Map<String,Float> score;
private Order order;
private String[] arr;
private Properties properties;
}
2. 基于set方法
2.1. 语法
- 基于set方法后面的值作为property中的name,不要误以为是属性名称。
- setName -> name,setAbc -> abc。
- property标签中的value属性无法与value标签同时存在于一个property标签中。
public class User{
private String name;
public void setTest(String value){
this.name = value;
}
}
<?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="user" class="com.cloud.domain.User">
<property name="test" value="123"></property>
</bean>
</beans>
2.1.1. 方式一
- property标签是基于set方法赋值
- property属性
<?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="user" class="com.cloud.domain.User">
<property name="name" value="123"></property>
</bean>
</beans>
2.1.2. 方式二
- 还是基于set方法的方式。
- 可以通过property标签的子标签value给属性赋值,替代property的value属性。
<?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="user" class="com.cloud.domain.User">
<property name="name">
<value>123</value>
</property>
</bean>
</beans>
2.2. String类型
2.2.1. 方式一
<?xml version="1.0" encoding="UTF-8"?>
<?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="user" class="com.cloud.domain.User">
<property name="name" value="zxy"></property>
</bean>
</beans>
2.2.2. 方式二
<?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="user" class="com.cloud.domain.User">
<property name="name">
<value>zxy</value>
</property>
</bean>
</beans>
2.3. 所有基础数据类型
2.3.1. 方式一
<?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="user" class="com.cloud.domain.User">
<property name="age" value="18"></property>
<property name="balance" value="123.45"></property>
</bean>
</beans>
2.3.2. 方式二
<?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="user" class="com.cloud.domain.User">
<property name="age">
<value>18</value>
</property>
<property name="balance">
<value>123.45</value>
</property>
</bean>
</beans>
2.4. list集合<基础类型>
2.4.1. 方式一
- list标签中的value-type属性表示List集合中的泛型类型。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="hobby">
<list value-type="java.lang.String">
<value>跳舞</value>
<value>唱歌</value>
<value>打游戏</value>
<value>敲代码</value>
</list>
</property>
</bean>
</beans>
2.4.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="hobby" ref="hobbyList"></property>
</bean>
<util:list id="hobbyList">
<value>跳舞1</value>
<value>唱歌2</value>
<value>打游戏3</value>
<value>敲代码4</value>
</util:list>
</beans>>
2.5. set集合<基础类型>
2.5.1. 方式一
- set标签中的value-type属性表示List集合中的泛型类型。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="address">
<set value-type="java.lang.String">
<value>湖南省</value>
<value>湖南省</value>
<value>江西省</value>
<value>湖北省</value>
</set>
</property>
</bean>
</beans>
2.5.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="address" ref="address"></property>
</bean>
<util:set id="address">
<value>湖南省</value>
<value>湖南省</value>
<value>江西省</value>
<value>湖北省</value>
</util:set>
</beans>
2.6. Map集合<基础类型,基础类型>
2.6.1. 方式一
- enry标签中的key-value,value-type属性表示map集合中的key,value泛型类型。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="score">
<map key-type="java.lang.String" value-type="java.lang.Float">
<entry key="数学" value="100"></entry>
<entry key="语文" value="99"></entry>
<entry key="英语" value="98"></entry>
</map>
</property>
</bean>
</beans>
2.6.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="score" ref="scoreMap"></property>
</bean>
<util:map id="scoreMap">
<entry key="数学" value="100"></entry>
<entry key="语文" value="99"></entry>
<entry key="英语" value="98"></entry>
</util:map>
</beans>
2.7. 其他自定义类型
2.7.1. 方式一
- 通过嵌套bean标签方式。
- 好处:只能够为当前属性服务,无法进行共享。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="order">
<bean class="com.cloud.domain.Order">
<property name="name" value="苹果"></property>
<property name="price" value="200"></property>
</bean>
</property>
</bean>
</beans>
2.7.2. 方式二
- 通过ref关联外部bean的方式。
- 好处:外部bean可以进行复用。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="order" class="com.cloud.domain.Order">
<property name="name" value="苹果"></property>
<property name="price" value="200"></property>
</bean>
<bean id="user" class="com.cloud.domain.User">
<property name="order" ref="order"></property>
</bean>
</beans>
2.8. 数组
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="arr">
<array>
<value>1</value>
<value>2</value>
<value>3</value>
<value>4</value>
</array>
</property>
</bean>
</beans>
2.9. properties
2.9.1. 方式一
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="properties">
<props>
<prop key="test1">test1</prop>
<prop key="test2">test2</prop>
<prop key="test3">test3</prop>
</props>
</property>
</bean>
</beans>
2.9.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="properties" ref="properties"></property>
</bean>
<util:properties id="properties">
<prop key="test1">test1</prop>
<prop key="test2">test2</prop>
<prop key="test3">test3</prop>
</util:properties>
</beans>
2.10. set方式代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="order" class="com.cloud.domain.Order">
<property name="name" value="苹果"></property>
<property name="price" value="200"></property>
</bean>
<bean id="user" class="com.cloud.domain.User">
<property name="name" value="zxy"></property>
<property name="age" value="18"></property>
<property name="balance" value="123.45"></property>
<property name="firstLetter" value="z"></property>
<property name="married" value="true"></property>
<property name="hobby" ref="hobbyList"></property>
<property name="address" ref="address"></property>
<property name="score" ref="scoreMap"></property>
<property name="order" ref="order"></property>
<property name="arr">
<array>
<value>1</value>
<value>2</value>
<value>3</value>
<value>4</value>
</array>
</property>
<property name="properties" ref="properties"></property>
</bean>
<util:list id="hobbyList">
<value>跳舞1</value>
<value>唱歌2</value>
<value>打游戏3</value>
<value>敲代码4</value>
</util:list>
<util:set id="address">
<value>湖南省</value>
<value>湖南省</value>
<value>江西省</value>
<value>湖北省</value>
</util:set>
<util:map id="scoreMap">
<entry key="数学" value="100"></entry>
<entry key="语文" value="99"></entry>
<entry key="英语" value="98"></entry>
</util:map>
<util:properties id="properties">
<prop key="test1">test1</prop>
<prop key="test2">test2</prop>
<prop key="test3">test3</prop>
</util:properties>
</beans>
3. 基于构造方法
3.1. 语法
3.1.1. 方式一
package com.cloud.domain;
public class User {
public User(String name) {
System.out.println(name);
}
}
<?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="user" class="com.cloud.domain.User">
<constructor-arg name="name" value="test"></constructor-arg>
</bean>
</beans>
3.1.2. 方式二
package com.cloud.domain;
public class User {
public User(String name) {
System.out.println(name);
}
}
3.2. String类型
3.2.1. 方式一
<?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="user" class="com.cloud.domain.User">
<constructor-arg name="name" value="zxy"></constructor-arg>
</bean>
</beans>
3.2.2. 方式二
<?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="user" class="com.cloud.domain.User">
<constructor-arg name="name">
<value>zxy</value>
</constructor-arg>
</bean>
</beans>
3.3. 所有基础数据类型
3.3.1. 方式一
<?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="user" class="com.cloud.domain.User">
<constructor-arg name="name" value="zxy"></constructor-arg>
<constructor-arg name="age" value="18"></constructor-arg>
<constructor-arg name="balance" value="123.45"></constructor-arg>
<constructor-arg name="firstLetter" value="z"></constructor-arg>
<constructor-arg name="married" value="true"></constructor-arg>
</bean>
</beans>
3.3.2. 方式二
<?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="user" class="com.cloud.domain.User">
<constructor-arg name="name">
<value>zxy</value>
</constructor-arg>
<constructor-arg name="age">
<value>18</value>
</constructor-arg>
<constructor-arg name="balance">
<value>123.89</value>
</constructor-arg>
<constructor-arg name="firstLetter">
<value>z</value>
</constructor-arg>
<constructor-arg name="married">
<value>true</value>
</constructor-arg>
</bean>
</beans>
3.4. list集合<基础类型>
3.4.1. 方式一
- list标签中的value-type属性表示List集合中的泛型类型。
<?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="user" class="com.cloud.domain.User">
<constructor-arg name="hobby">
<list value-type="java.lang.String">
<value>跳舞1</value>
<value>唱歌2</value>
<value>打游戏3</value>
<value>敲代码4</value>
</list>
</constructor-arg>
</bean>
</beans>
3.4.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="name">
<value>zxy</value>
</constructor-arg>
<constructor-arg name="age">
<value>18</value>
</constructor-arg>
<constructor-arg name="balance">
<value>123.89</value>
</constructor-arg>
<constructor-arg name="firstLetter">
<value>z</value>
</constructor-arg>
<constructor-arg name="married">
<value>true</value>
</constructor-arg>
<constructor-arg name="hobby" ref="hobbyList"></constructor-arg>
</bean>
<util:list id="hobbyList">
<value>跳舞2</value>
<value>唱歌2</value>
<value>打游戏2</value>
<value>敲代码2</value>
</util:list>
</beans>
3.5. set集合<基础类型>
3.5.1. 方式一
- set标签中的value-type属性表示List集合中的泛型类型。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="address">
<set value-type="java.lang.String">
<value>湖南省</value>
<value>湖南省</value>
<value>江西省</value>
<value>湖北省</value>
</set>
</constructor-arg>
</bean>
</beans>
3.5.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="address" ref="address"></constructor-arg>
</bean>
<util:set id="address">
<value>湖南省1</value>
<value>湖南省1</value>
<value>江西省2</value>
<value>湖北省2</value>
</util:set>
</beans>
3.6. Map集合<基础类型,基础类型>
3.6.1. 方式一
- enry标签中的key-value,value-type属性表示map集合中的key,value泛型类型。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="score">
<map key-type="java.lang.String" value-type="java.lang.Float">
<entry key="数学" value="100"></entry>
<entry key="语文" value="99"></entry>
<entry key="英语" value="98"></entry>
</map>
</constructor-arg>
</bean>
</beans>
3.6.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<property name="score" ref="scoreMap"></property>
</bean>
<util:map id="scoreMap">
<entry key="数学" value="100"></entry>
<entry key="语文" value="99"></entry>
<entry key="英语" value="98"></entry>
</util:map>
</beans>
3.7. 其他自定义类型
3.7.1. 方式一
- 通过嵌套bean标签方式。
- 好处:只能够为当前属性服务,无法进行共享。
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="order">
<bean class="com.cloud.domain.Order">
<property name="name" value="苹果"></property>
<property name="price" value="200"></property>
</bean>
</constructor-arg>
</bean>
</beans>
3.7.2. 方式二
- 通过ref关联外部bean的方式。
- 好处:外部bean可以进行复用。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="order" class="com.cloud.domain.Order">
<property name="name" value="苹果"></property>
<property name="price" value="200"></property>
</bean>
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="order" ref="order"></constructor-arg>
</bean>
</beans>
3.8. 数组
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="arr">
<array>
<value>1</value>
<value>2</value>
<value>3</value>
<value>4</value>
</array>
</constructor-arg>
</bean>
</beans>
3.9. properties
3.9.1. 方式一
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="properties">
<props>
<prop key="test1">value1</prop>
<prop key="test2">value2</prop>
<prop key="test3">value3</prop>
<prop key="test4">value4</prop>
</props>
</constructor-arg>
</bean>
</beans>
3.9.2. 方式二
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="properties" ref="properties"></constructor-arg>
</bean>
<util:properties id="properties">
<prop key="test1">value1</prop>
<prop key="test2">value2</prop>
<prop key="test3">value3</prop>
<prop key="test4">value4</prop>
</util:properties>
</beans>
3.10. 构造方式代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<bean id="order" class="com.cloud.domain.Order">
<property name="name" value="苹果"></property>
<property name="price" value="200"></property>
</bean>
<bean id="user" class="com.cloud.domain.User">
<constructor-arg name="name" value="zxy"></constructor-arg>
<constructor-arg name="age" value="18"></constructor-arg>
<constructor-arg name="balance" value="123.45"></constructor-arg>
<constructor-arg name="firstLetter" value="z"></constructor-arg>
<constructor-arg name="married" value="true"></constructor-arg>
<constructor-arg name="hobby">
<list value-type="java.lang.String">
<value>跳舞1</value>
<value>唱歌2</value>
<value>打游戏3</value>
<value>敲代码4</value>
</list>
</constructor-arg>
<constructor-arg name="address">
<set value-type="java.lang.String">
<value>湖南省</value>
<value>湖南省</value>
<value>江西省</value>
<value>湖北省</value>
</set>
</constructor-arg>
<constructor-arg name="score">
<map key-type="java.lang.String" value-type="java.lang.Float">
<entry key="数学" value="100"></entry>
<entry key="语文" value="99"></entry>
<entry key="英语" value="98"></entry>
</map>
</constructor-arg>
<constructor-arg name="order" ref="order"></constructor-arg>
<constructor-arg name="arr">
<array>
<value>1</value>
<value>2</value>
<value>3</value>
<value>4</value>
</array>
</constructor-arg>
<constructor-arg name="properties" ref="properties"></constructor-arg>
</bean>
<util:properties id="properties">
<prop key="test1">test1</prop>
<prop key="test2">test2</prop>
<prop key="test3">test3</prop>
</util:properties>
</beans>