• 宋体集合Spring装配集合的四个方法及实现


    近期一直在查找宋体集合之类的问题,下午正好有机会和大家讨论一下.

        四种配装集合

        在这我我直接用util schema集合,用util签标

        需只要把util的约束加进去就行,引进其他的也是这样直接加就能够了

        <beans xmlns="http://www.springframework.org/schema/beans"

        xmlns:util="http://www.springframework.org/schema/util"

        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

                   http://www.springframework.org/schema/util

                   http://www.springframework.org/schema/util/spring-util.xsd">

        第一种 Set集合

        <bean 

      id="collectionBean" class="www.csdn.spring01.collection.CollectionBean">

        <property name="sets">

        <!--set集合如果不引用util schema集合 直接写<set>集合就行 -->

        <util:set> 

        <value>1</value>

        <value>2</value>

        <value>3</value>

        <value>4</value>

        <value>5</value>

        <value>6</value>

        </util:set>

        </property>

        第二种list集合

        <property name="lists">

        <util:list>

        <ref bean="u1" />

        <ref bean="u2" />

        <ref bean="u3" />

        </util:list>

        </property>

        第三种map集合

        <property name="maps">

        <util:map>

        <entry key="1" value-ref="u1" />

        <entry key="2" value-ref="u2" />

        <entry key="3">

        <ref bean="u3" />

        </entry>

        </util:map>

        </property>

        第四种properties集合

        <property name="properties">

          <util:properties>

             <prop key="1">JDBC:ORACLE</prop>

             <prop key="2">JDBC:MYSQL</prop>

             <prop key="3">JDBC:SQL</prop>

          </util:properties>

        </property>

        </bean>

        引用的其他的类

        <bean id="u1" class="www.csdn.spring01.collection.User">

        <property name="name" value="刘--" />

        <property name="age" value="11" />

        </bean>

        <bean id="u2" class="www.csdn.spring01.collection.User">

        每日一道理
    风,那么轻柔,带动着小树、小草一起翩翩起舞,当一阵清风飘来,如同母亲的手轻轻抚摸自己的脸庞,我喜欢那种感觉,带有丝丝凉意,让人心旷神怡。享受生活,不一定要有山珍海味、菱罗绸缎为伴,大自然便是上帝所赐予人类最为珍贵的。

        <property name="name" value="2--" />

        <property name="age" value="22" />

        </bean>

        <bean id="u3" class="www.csdn.spring01.collection.User">

        <property name="name" value="2--" />

        <property name="age" value="33" />

        </bean>

        Bean

        public class CollectionBean {

        // --------set----------

        private Set<String> sets;;

        public Set<String> getSets() {

        return sets;

        }

        public void setSets(Set<String> sets) {

        this.sets = sets;

        }

        // --------list----------

        private List<User> lists;

        public List<User> getLists() {

        return lists;

        }

        public void setLists(List<User> lists) {

        this.lists = lists;

        }

        //--------map-----------

        private Map<Integer,User> maps;

        public Map<Integer, User> getMaps() {

        return maps;

        }

        public void setMaps(Map<Integer, User> maps) {

        this.maps = maps;

        }

        //------properties-------

        private Properties properties;

        public Properties getProperties() {

        return properties;

        }

        public void setProperties(Properties properties) {

        this.properties = properties;

        }

        package www.csdn.spring01.collection;

        public class User {

        private String name;

        private Integer age;

        public String getName() {

        return name;

        }

        public void setName(String name) {

        this.name = name;

        }

        public Integer getAge() {

        return age;

        }

        public void setAge(Integer age) {

        this.age = age;

        }

        }

        测试法方:

        package www.csdn.spring01.collection;

        import static org.junit.Assert.*;

        import java.util.Iterator;

        import java.util.List;

        import java.util.Map;

        import java.util.Map.Entry;

        import java.util.Properties;

        import java.util.Set;

        import org.junit.Test;

        import org.springframework.context.ApplicationContext;

        import org.springframework.context.support.ClassPathXmlApplicationContext;

        public class CollectionTest {

        @Test

        public void testSet() {

        ApplicationContext context = new ClassPathXmlApplicationContext(

        "classpath:spring-collection.xml");

        CollectionBean collectionBean = context.getBean("collectionBean",

        CollectionBean.class);

        Set<String> sets = collectionBean.getSets();

        Iterator iterator = sets.iterator();

        while (iterator.hasNext()) {

        System.out.println(iterator.next());

        }

        }

        @Test

        public void testList() {

        ApplicationContext context = new ClassPathXmlApplicationContext(

        "classpath:spring-collection.xml");

        CollectionBean collectionBean = context.getBean("collectionBean",

        CollectionBean.class);

        List<User> lists = collectionBean.getLists();

        for (User list : lists) {

        System.out.println(list.getName() + "-------" + list.getAge());

        }

        }

        @Test

        public void testMap() {

        ApplicationContext context = new ClassPathXmlApplicationContext(

        "classpath:spring-collection.xml");

        CollectionBean collectionBean = context.getBean("collectionBean",

        CollectionBean.class);

        Map<Integer, User> maps = collectionBean.getMaps();

        // --通过set法方取获到有所的key

        Set<Integer> setKeys = maps.keySet();

        // --遍历key

        Iterator<Integer> iterator = setKeys.iterator();

        while (iterator.hasNext()) {

        // 失掉一个详细的键值

        Integer key = iterator.next();

        // 通过map集合的get(key)法方取获key的值

        User user = maps.get(key);

        System.out.println(key + "------" + user.getName() + "-----"

        + user.getAge());

        }

        }

        @Test

        public void testMap2() {

        ApplicationContext context = new ClassPathXmlApplicationContext(

        "classpath:spring-collection.xml");

        CollectionBean collectionBean = context.getBean("collectionBean",

        CollectionBean.class);

        Map<Integer, User> maps = collectionBean.getMaps();

        // --通过set法方取获到有所的key

        Set<Entry<Integer,User>> setKeys = maps.entrySet();

        // --遍历key

        Iterator<Entry<Integer, User>> iterator = setKeys.iterator();

        while (iterator.hasNext()) {

        // 失掉一个详细的键值

        Entry<Integer, User> entry = iterator.next();

        // 通过map集合的get(key)法方取获key的值

        System.out.println(entry.getKey() + "------" + entry.getValue().getName() + "-----"

        + entry.getValue().getAge());

        }

        }

        @Test

        public void testProperties() {

        ApplicationContext context = new ClassPathXmlApplicationContext(

        "classpath:spring-collection.xml");

        CollectionBean collectionBean = context.getBean("collectionBean",

        CollectionBean.class);

        Properties properties = collectionBean.getProperties();

        //失掉这个结合键值的keyset集合

        Set<String> setProp = properties.stringPropertyNames();

      Iterator<String> iterator = setProp.iterator();

      while(iterator.hasNext()){

      String key = iterator.next();

      System.out.println(key+"-----"+properties.getProperty(key));

      }

        }

        }

    文章结束给大家分享下程序员的一些笑话语录: 手机终究会变成PC,所以ip会比wm更加畅销,但是有一天手机强大到一定程度了就会发现只有wm的支持才能完美享受。就好比树和草,草长得再高也是草,时间到了条件成熟了树就会窜天高了。www.ishuo.cn

  • 相关阅读:
    yum只下载不安装的方法
    在VS2008下编译Qt4.4.x
    Linux sh脚本异常:bad interpreter: No such file or directory
    动态链接库dll,静态链接库lib, 导入库lib 转
    Accumulation Buffer(累积缓存)
    mysql中ip和整数的转换
    开车撞人了!
    windows 下getc()返回0x1A表示EOF
    NPC问题
    关于普华永道、麦肯锡和IBM的笑话
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3043264.html
Copyright © 2020-2023  润新知