spring 集合注入格式
数组
List
Set
Map
properties
案例
package org.example.dao.impl;import org.example.dao.BookDao;import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;public class BookDaoImpl implements BookDao {private int[] array;private List<String> list;private Set<String> set;private Map<String, String> map;private Properties properties;public void setArray(int[] array) {this.array = array;}public void setList(List<String> list) {this.list = list;}public void setSet(Set<String> set) {this.set = set;}public void setMap(Map<String, String> map) {this.map = map;}public void setProperties(Properties properties) {this.properties = properties;}public void save() {System.out.println(this.array);System.out.println(this.list);System.out.println(this.set);System.out.println(this.map);System.out.println(this.properties);}
}
<?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="bookDao" class="org.example.dao.impl.BookDaoImpl"><property name="array"><array><value>10</value><value>20</value><value>30</value></array></property><property name="list"><list><value>aaa</value><value>bbb</value><value>ccc</value></list></property><property name="set"><set><value>aaa</value><value>bbb</value><value>ccc</value><value>ccc</value></set></property><property name="map"><map><entry key="name" value="alex"/><entry key="city" value="上海"/></map></property><property name="properties"><props><prop key="name">alex</prop><prop key="city">上海</prop></props></property></bean></beans>
输出
[I@22635ba0
[aaa, bbb, ccc]
[aaa, bbb, ccc]
{name=alex, city=上海}
{city=上海, name=alex}