• 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");
    }
    }

  • 相关阅读:
    构建自己的外汇智能交易系统
    EA范例
    读书札记:加拿大元因素
    预计欧元近期将“绝境大反攻”
    读书札记:新西兰元因素
    在新的一年里开启新的人生
    旧文重发:行在道上,从局部到全局——与师者高焕堂、赵善中先生谈《大道至简》
    与邹欣先生就《大道至简》一书中的两个主要问题的讨论
    《大道至简》一书第三版,与编辑就本书写作风格的讨论
    与读者们谈谈《大道至简》这五年
  • 原文地址:https://www.cnblogs.com/wenwenzuiniucha/p/8605022.html
Copyright © 2020-2023  润新知