zoukankan      html  css  js  c++  java
  • set map properties对象的遍历

    public class TestCase {
    @Test
    public void testEggAndRice(){
    // EggAndRice eggAndRice = new EggAndRice();
    // System.out.println(eggAndRice);
    String cfg = "applicationCotext.xml";
    ApplicationContext ac = new ClassPathXmlApplicationContext(cfg);
    EggAndRice eggAndRice = (EggAndRice) ac.getBean("eggAndRice");
    System.out.println(eggAndRice);
    }
    @Test
    public void testLogin(){
    String cfg = "applicationCotext.xml";
    ApplicationContext ac = new ClassPathXmlApplicationContext(cfg);
    DataSource ds = (DataSource) ac.getBean("dataSource");
    System.out.println(ds.getConnection());

    // UserDao userDao = (UserDao) ac.getBean("userDao");
    // System.out.println(userDao.findByUsername("zs"));
    // UserService userService = (UserService) ac.getBean("userService");
    // String message = userService.login("aa", "123a");
    // System.out.println(message);
    }
    /**
    *
    * @Title: testExamBean
    * @Description: TODO(这里用一句话描述这个方法的作用)
    * @param name
    * @return String 返回类型
    * @author wmj
    * @throws
    */
    @Test
    public void testExamBean(){
    String cfg = "applicationCotext.xml";
    ApplicationContext ac = new ClassPathXmlApplicationContext(cfg);
    ExampleBean exam = (ExampleBean) ac.getBean("exam");
    System.out.println(exam.getId()+"号的工作是"+exam.getJob()+",他每个月工资是"+exam.getSal()+",他现在"+(exam.getIsMarry() ?"已婚":"单身") );
    }
    /**
    *
    * @Title: testExamBean2
    * @Description: 集合属性值注入
    * @param 设定文件
    * @return void 返回类型
    * @author wmj
    * @throws
    */
    @Test
    public void testExamBean2(){
    String cfg = "applicationCotext.xml";
    ApplicationContext ac = new ClassPathXmlApplicationContext(cfg);
    ExampleBean exam = (ExampleBean) ac.getBean("exam2");
    List<Object> objs = exam.getObjs();
    for(Object o:objs){
    //System.out.println(o);
    }

    Set<String> sets = exam.getSets();
    for(String s:sets){
    //System.out.println(s);
    }

    Map<String,Object> maps = exam.getMaps();
    //返回当前map键值对的所有key值
    Set<String> keys = maps.keySet();
    for(String k:keys){
    //System.out.println("key="+k+",value="+maps.get(k));
    }

    Set<Entry<String,Object>> ens = maps.entrySet();
    for(Entry<String,Object> e:ens){
    //System.out.println("key="+e.getKey()+",value="+e.getValue());
    }

    Properties props = exam.getProps();
    Set<Object> ps = props.keySet();
    for(Object k:ps){
    System.out.println("key="+k+",value="+props.get(k));
    }
    }
    @Test
    public void testExamBean3(){
    String cfg = "applicationCotext.xml";
    ApplicationContext ac = new ClassPathXmlApplicationContext(cfg);
    List<Object> lists = (List<Object>) ac.getBean("list");
    for(Object o:lists){
    //System.out.println(o);
    }

    Properties props = (Properties) ac.getBean("jdbc");
    Set<Object> ps = props.keySet();
    for(Object k:ps){
    System.out.println("key="+k+",value="+props.get(k));
    }
    // ExampleBean exam = (ExampleBean) ac.getBean("exam3");
    }
    }

  • 相关阅读:
    slf4j使用
    centos 安装 redis
    centos安装单机zookeeper
    activemq消息重发机制[转]
    maven 指定工程的 jdk 版本及编译级别
    Elasticsearch-索引新数据(创建索引、添加数据)
    Elasticsearch-数据的存储、搜索(干货)
    Yarn-本地获取任务日志
    Hive-Container killed by YARN for exceeding memory limits. 9.2 GB of 9 GB physical memory used. Consider boosting spark.yarn.executor.memoryOverhead.
    Elasticsearch-安装、日志解读
  • 原文地址:https://www.cnblogs.com/wenwenzuiniucha/p/8605022.html
Copyright © 2011-2022 走看看