标签:schema org data 数组 password 数据 pojo vat list
【环境搭建】
1.真实测试对象
2.复杂类型
@Data
public class Student {
private String name;
private Address address;
private String[] books;
private List<String> hobbys;
private Map<String,String> card;
private Set<String> games;
private String wife;
private Properties info;
}
@Data
public class Address {
private String address;
}
3.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
https://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 使用Spring来创建对象 在Spring中这些都称为Bean
Hello hell = new Hello()
bean = 对象 new Hello()
id=变量名 hello
class=new Hello()
property 相当于给对象中的属性设置一个值
ref:引用Spring容器中创建好的对象id
Values: 具体的值,基本数据类型和String
-->
<bean id="student" class="com.saxon.pojo.Student">
<!--第一种:普通值注入,value-->
<property name="name" value="张三"/>
<!--第二种:对象bean注入,ref引入-->
<property name="address" ref="address"/>
<!--第三种:数组注入,array-->
<property name="books">
<array>
<value>Java</value>
<value>Spring</value>
<value>SpringMVC</value>
<value>SpringBoot</value>
</array>
</property>
<!--第四种:list集合注入,list-->
<property name="hobbys">
<list>
<value>吃饭</value>
<value>睡觉</value>
<value>写代码</value>
</list>
</property>
<!--第五种:map注入,map entry -->
<property name="card">
<map key-type="java.lang.String" value-type="java.lang.String">
<entry key="1" value="阿里巴巴规范"/>
<entry key="2" value="数据库优化"/>
</map>
</property>
<!--第六种:set注入 -->
<property name="games">
<set>
<value>LOL</value>
<value>DNF</value>
</set>
</property>
<!--第七种:空值null注入 -->
<property name="wife">
<null/>
</property>
<!--第八种:Properties注入-->
<property name="info">
<props>
<prop key="username">root</prop>
<prop key="password">123456</prop>
</props>
</property>
</bean>
<bean id="address" class="com.saxon.pojo.Address">
<property name="address" value="杭州"/>
</bean>
</beans>
标签:schema org data 数组 password 数据 pojo vat list
原文地址:https://www.cnblogs.com/saxonsong/p/14899051.html