Spring-集合注入实例

本文阅读 1 分钟
首页 代码,Java 正文

img

✨博客主页:👉 不会压弯的小飞侠 ✨欢迎关注:👉点赞👍收藏⭐留言✒ ✨系列专栏:👉 spring专栏 ✨如果觉得博主的文章还不错的话,请三连支持一下博主。 ✨欢迎大佬指正,一起学习!一起加油!

✨BookDao接口

package com.jkj.dao;
public interface BookDao { 
    void save();
}

✨BookDaoImpl实现类

package com.jkj.dao.impl;

import com.jkj.dao.BookDao;

import java.util.*;

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("BookDao...");
        System.out.println("遍历数组:"+ Arrays.toString(array));
        System.out.println("遍历List:"+list);
        System.out.println("遍历Set:"+set);
        System.out.println("遍历Map:"+map);
        System.out.println("遍历Properties:"+properties);

    }
}

✨applicationContext.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="bookDao" class="com.jkj.dao.impl.BookDaoImpl">
        <property name="array">
            <array>
                <value>12</value>
                <value>14</value>
                <value>16</value>
            </array>
        </property>
        <property name="list">
            <list>
                <value>小马哥</value>
                <value>Tom</value>
                <value>小飞侠</value>
            </list>
        </property>
        <property name="set">
            <set>
                <value>Cat</value>
                <value>Cat</value>
                <value>Tom</value>
                <value>Jack</value>
            </set>
        </property>
        <property name="map">
            <map>
               <entry key="1" value="34"></entry>
                <entry key="2" value="小飞侠"></entry>
                <entry key="3" value="Rack"></entry>
            </map>
        </property>
        <property name="properties">
            <props>
               <prop key="1">科比</prop>
                <prop key="2">詹姆斯</prop>
                <prop key="3">哈登</prop>
            </props>
        </property>


    </bean>

</beans>

✨Test测试类

import com.jkj.dao.BookDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test { 
    public static void main(String[] args) { 
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookDao bookDao = (BookDao) context.getBean("bookDao");
        bookDao.save();
    }
}
/* BookDao... 遍历数组:[12, 14, 16] 遍历List:[小马哥, Tom, 小飞侠] 遍历Set:[Cat, Tom, Jack] 遍历Map:{1=34, 2=小飞侠, 3=Rack} 遍历Properties:{3=哈登, 2=詹姆斯, 1=科比} */
本文为互联网自动采集或经作者授权后发布,本文观点不代表立场,若侵权下架请联系我们删帖处理!文章出自:https://blog.csdn.net/qq_43514330/article/details/125424481
-- 展开阅读全文 --
安全面试之XSS(跨站脚本攻击)
« 上一篇 07-24

发表评论

成为第一个评论的人

热门文章

标签TAG

最近回复