Пример коллекций Spring (список, набор, карта и свойства)
Примеры Spring, чтобы показать вам, как вводить значения в тип коллекций (List, Set, Map и Properties). Поддерживаются 4 основных типа коллекций:
-
Список - <список />
-
Set -
-
Карта - <карта />
-
Свойства -
Весенние бобы
Объект Customer с четырьмя свойствами коллекции.
package com.example.common; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; public class Customer { private List
Смотрите различные фрагменты кода для объявления коллекции в файле конфигурации бина.
3. Пример карты
4. Пример свойств
Файл конфигурации bean-компонента Full Spring.
Запустить его…
package com.example.common; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class App { public static void main( String[] args ) { ApplicationContext context = new ClassPathXmlApplicationContext("SpringBeans.xml"); Customer cust = (Customer)context.getBean("CustomerBean"); System.out.println(cust); } }
Выход
Customer [ lists=[ 1, Person [address=address 1, age=28, name=example1], Person [address=address, age=28, name=exampleList] ], maps={ key 1=1, key 2=Person [address=address 1, age=28, name=example1], key 3=Person [address=address, age=28, name=exampleMap] }, pros={[email protected], [email protected]}, sets=[ 1, Person [address=address 1, age=28, name=example1], Person [address=address, age=28, name=exampleSet]] ]
Скачать исходный код
Скачать -Spring-Collection-Example.zip (6 КБ)