您现在的位置是:首页 > 个人日记个人日记
spring-05-复杂数据类型注入
2019-02-03 18:08:28【个人日记】499人已围观
简介对复杂数据类型进行注入
复杂数据类型注入
创建一个Student对象
package com.huangxin.spring.model;
public class Student {
private String name;
private int age;
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
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;
}
}
复杂数据
package com.huangxin.spring.model;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class CollectionBean {
private List<String> list;
private Set<String> set;
private String array[] = new String[3];
private Map<String, Object> map;
private Properties properties;
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public Set<String> getSet() {
return set;
}
public void setSet(Set<String> set) {
this.set = set;
}
public String[] getArray() {
return array;
}
public void setArray(String[] array) {
this.array = array;
}
public Map<String, Object> getMap() {
return map;
}
public void setMap(Map<String, Object> map) {
this.map = map;
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
}
# 重点
xml配置
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="collectionBean" class="com.huangxin.spring.model.CollectionBean">
<property name="array">
<array>
<value>Java</value>
<value>C#</value>
<value>Android</value>
</array>
</property>
<property name="list">
<list>
<value>Java</value>
<value>C#</value>
<value>Android</value>
</list>
</property>
<property name="set">
<set>
<value>Java</value>
<value>C#</value>
<value>Android</value>
</set>
</property>
<property name="map">
<map>
<entry key="k1" value="java"></entry>
<entry key="k2" value="android"></entry>
<entry key="k3" value-ref="student"></entry>
</map>
</property>
<property name="properties">
<props>
<prop key="k1">Java</prop>
<prop key="k2">C#</prop>
</props>
</property>
</bean>
<bean id="student" class="com.huangxin.spring.model.Student">
<property name="age" value="18"></property>
<property name="name" value="黄鑫"></property>
</bean>
</beans>
以上为大部分数据的注入,仔细看配置
Tags: JavaWeb
上一篇: mybatis-02-CRUD简单操作
下一篇: spring-01-快速上手
相关文章
随机图文
评论区
2024-12-21 19:32:38
站长
没有登录功能是为了方便大家留言,但留言接口现在被恶意攻击,将关闭留言接口,如有疑问,请联系我的QQ 1538933906/同微信