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

  • 相关阅读:
    Linux正则和grep命令
    Linux用户和权限
    XP下安装ubuntu
    Linux命令行和shell编程
    Linux软件安装及基本概念
    Linux历史,安装,分区,版本
    Eric Linux
    批量插入数据
    Django 相关
    标签,
  • 原文地址:https://www.cnblogs.com/wenwenzuiniucha/p/8605022.html
Copyright © 2011-2022 走看看