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

posted @ 2018-03-19 21:33  傲云萧雨  阅读(125)  评论(0编辑  收藏  举报