spring的数组,list,set,map

 使用的是set注入:

package com.chen;

import java.util.*;

public class Stu {
    //1.数组类型
    private   String[] courses;
    //2.list集合类型属性
    private List<String> list;
    //3.map集合类型属性
    Map<String,Object> map;
    //4.set集合类型的 属性
    private Set<String> set;

    public List<Course> courseList;

    public void setCourseList(List<Course> courseList) {
        this.courseList = courseList;
    }

    public void setCourses(String[] courses) {
        this.courses = courses;
    }

    public void setList(List<String> list) {
        this.list = list;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public void setSet(Set<String> set) {
        this.set = set;
    }
    public void  show(){
        for (String cours : courses) {
            System.out.println("数组==》"+cours);
        }
        for (String s : list) {
            System.out.println("list==>"+s);
        }
        for (String s : set) {
            System.out.println("set==>"+s);
        }

        Set<String> set = map.keySet();
        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()){
            Object next = iterator.next();
            Object o = map.get(next);
            System.out.println(next+":"+o);

        }

        for (Course course : courseList) {
            System.out.println("courseList==>"+course);
        }
    }
}

这是xml配置,里面分别展示了几种类型的value值的写法

<?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="stu" class="com.chen.Stu">
    <property name="courses">
        <array>
            <value>java课程</value>
            <value>英语课程</value>
            <value>数学课程</value>
            <value>体育</value>
        </array>
    </property>

    <property name="list">
        <list>
            <value>香蕉</value>
            <value>苹果</value>
            <value>橘子</value>
        </list>
    </property>
    <property name="set">
        <set>
          <value>足球</value>
          <value>篮球</value>
          <value>羽毛球</value>
        </set>
    </property>
    <property name="map">
        <map>
            <entry key="英语" value="89"></entry>
            <entry key="数学" value="190"></entry>
            <entry key="身高" value="178"></entry>
        </map>
    </property>


    <!--注入list集合类型,值是对象-->
    <property name="courseList">
        <list>
            <ref bean="course1" ></ref>
            <ref bean="course2" ></ref>
            <ref bean="course3" ></ref>
        </list>
    </property>
</bean>
    <bean id="course1" class="com.chen.Course">
        <property name="courname" value="化学"></property>
    </bean>
    <bean id="course2" class="com.chen.Course">
        <property name="courname" value="政治"></property>
    </bean>
    <bean id="course3" class="com.chen.Course">
        <property name="courname" value="物理"></property>
    </bean>
</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值