11级_Java_曹建波 04.25 Spring便历Collection集合
来源:互联网 发布:物流抢单软件 编辑:程序博客网 时间:2024/06/08 06:29
示例
User.java
package www.csdn.spring.collection.set;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;}}
CollectionBean.java
package www.csdn.spring.collection.set;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;public class CollectionBean {public Set<String> sets;public void setSets(Set<String> sets) {this.sets = sets;}public CollectionBean() {super();System.out.println("=================================");}public List<User> users;public void setUsers(List<User> users) {this.users = users;}public Map<Integer,User> map;public void setMap(Map<Integer, User> map) {this.map = map;}public Properties props;public void setProps(Properties props) {this.props = props;}}
TestBean.java
package www.csdn.spring.collection.set;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 TestBean {@Testpublic void testSets(){ApplicationContext context=new ClassPathXmlApplicationContext("classpath:spring-collection.xml");CollectionBean bean=context.getBean("collectionBean",CollectionBean.class);Set<String> sets=bean.sets;Iterator<String> it=sets.iterator();while(it.hasNext()){System.out.println(it.next());}System.out.println("----------------------List--------------");List<User> users=bean.users;for(User u:users){System.out.println(u.getName()+"------"+u.getAge());}System.out.println("----------------------map--------------");Map<Integer, User> map=bean.map;Set<Integer> setKeys=map.keySet();Iterator<Integer> itKeys=setKeys.iterator();while(itKeys.hasNext()){Integer key=itKeys.next();User user=map.get(key);System.out.println(key+":--"+user.getName()+"--"+user.getAge());}System.out.println("----------------------map2--------------");Set<Entry<Integer,User>> setentry=map.entrySet();Iterator<Entry<Integer, User>> itentry=setentry.iterator();while(itentry.hasNext()){Entry<Integer, User> entry=itentry.next();System.out.println(entry.getKey()+"----"+entry.getValue().getName()+"----"+entry.getValue().getAge());}System.out.println("----------------------props--------------");Properties props=bean.props;Set<String> setprops=props.stringPropertyNames();Iterator<String> keystr=setprops.iterator();while(keystr.hasNext()){String key=keystr.next();System.out.println(key+"----"+props.getProperty(key));}} }
spring-collection.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"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"><bean id="collectionBean" class="www.csdn.spring.collection.set.CollectionBean"scope="singleton" lazy-init="default"><property name="sets"><set><value>哈哈哈</value><value>嘿嘿嘿</value><value>呵呵呵</value><value>ASDA</value><value>哈啊啊是是哈</value><value>哈啊三哈</value></set></property><property name="users"><array><ref bean="u1" /><ref bean="u2" /><ref bean="u3" /><ref bean="u4" /></array></property><property name="map"><map><entry key="1" value-ref="u1" /><entry key="2"><ref bean="u2" /></entry><entry key="3" value-ref="u3" /></map></property><property name="props"><props><prop key="1">jdbc:mysql</prop><prop key="2">jdbc:oracle</prop><prop key="3">jdbc:access</prop></props></property></bean><bean id="u1" class="www.csdn.spring.collection.set.User"><property name="name" value="张三" /><property name="age" value="28" /></bean><bean id="u2" class="www.csdn.spring.collection.set.User"><property name="name" value="李四" /><property name="age" value="28" /></bean><bean id="u3" class="www.csdn.spring.collection.set.User"><property name="name" value="王五" /><property name="age" value="30" /></bean><bean id="u4" class="www.csdn.spring.collection.set.User"><property name="name" value="马六" /><property name="age" value="28" /></bean></beans>
- 11级_Java_曹建波 04.25 Spring便历Collection集合
- 11级_Java_曹建波4.25 Java中的集合类
- 11级_Java_曹建波 05.06 spring aop术语概述
- 11级_Java_曹建波 04.23 初步认识Spring,为什么要使用Spring及优势
- 11级_Java_曹建波 04.24 Spring的配置、生命周期、依赖注入bean的操作
- 11级_Java_曹建波 05.06 Spring的autowire自动装配bean的四种方式
- 11级_Java_曹建波4.07 方法
- 11级_Java_曹建波3.29 控制流程
- 11级_Java_曹建波4.11 接口
- 11级_Java_曹建波4.17 数组
- 11级_Java_曹建波5.02 GUI程序设计
- 11级_Java_曹建波5.04 事件适配器
- 11级_Java_曹建波5.10 字符流
- 11级_Java_曹建波5.14 字节流
- 11级_Java_曹建波5.18 多线程
- 11级_Java_曹建波5.30 WHERE子句
- 11级_Java_曹建波6.05 索引
- 11级_Java_曹建波6.08 存储过程
- post提交 打开新页面 拦截问题
- Apache Thrift - 可伸缩的跨语言服务开发框架
- URLConnection参数详解
- hadoop远程客户端安装配置、多用户权限配置
- objective-c 获取当前苹果设备的语言
- 11级_Java_曹建波 04.25 Spring便历Collection集合
- Android中保存界面状态
- oracle 11g 迁移到oracle 10g
- ***没有规则可以创建***
- GridView中后台添加样式和效果
- EditText中插入图片
- memcache 内存使用详解
- 让openscales支持Googlemap
- 一个效果非常不错的JAVA数据库连接池