1. 程式人生 > >spring 框架 list、set、map、Properties陣列注入

spring 框架 list、set、map、Properties陣列注入

package com.zxk.test;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zxk.entity.SystemIoc;
import com.zxk.entity.Usb;

public class Test {
public static void main(String[] args) {
//讀取spring配置檔案
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
//獲取表示的物件
SystemIoc systemIoc = (SystemIoc) context.getBean("systemIoc");
//輸出內容
System.out.println("---------基本型別陣列輸出--------------");
String[] strings = systemIoc.getStrings();
for (String string : strings) {
System.out.println(string);
}

System.out.println("---------物件型別陣列輸出--------------");

Usb[] usbs = systemIoc.getUsbs();
for (Usb usb : usbs) {
System.out.println(usb.getSize());
}

System.out.println("---------list無參型別陣列輸出--------------");

List list1 = systemIoc.getLists1();
System.out.println(list1.get(2));

System.out.println("---------list泛型型別陣列輸出--------------");

List<Integer> list2 = systemIoc.getLists2();
for (Integer integer : list2) {
System.out.println(integer);
}

System.out.println("---------list物件型別陣列輸出--------------");

List<Usb> list3 = systemIoc.getLists3();
for (Usb usb : list3) {
System.out.println(usb.getSize());
}

System.out.println("---------set物件型別陣列輸出--------------");

Set<Usb> sets = systemIoc.getSets();
for (Usb usb : sets) {
System.out.println(usb.getSize());
}

System.out.println("---------Map陣列輸出--------------");

Map<String,Usb> maps = systemIoc.getMaps();
for (Usb usb : maps.values()) {
System.out.println(usb.getSize());
}

System.out.println("---------Properties陣列輸出--------------");

Properties pros = systemIoc.getPros();
for (Object str : pros.values()) {
System.out.println(str);
}
}
}