spring 3配置文件中如何注入map list set等类型
来源:互联网 发布:果敢 知乎 编辑:程序博客网 时间:2024/06/14 00:07
首先写个 javabean类吧,如下
package com.bean;import java.util.List;import java.util.Map;import java.util.Properties;import java.util.Set;public class MessageBean {private String username;private String password;private int size;private List<String> citys;private Set<String> friends;private Map<Integer,String> books;private Properties props;public void setProps(Properties props) {this.props = props;}public void setFriends(Set<String> friends) {this.friends = friends;}public void setSize(int size) {this.size = size;}public void setPassword(String password) {this.password = password;}public void setUsername(String username) {this.username = username;}public void show(){System.out.println(username);System.out.println(password);System.out.println(size);System.out.println("----------");for(String str:citys){System.out.println(str);}System.out.println("----------");for(String str:friends){System.out.println(str);}System.out.println("---------");Set<Integer> keys = books.keySet();for(Integer key:keys){System.out.println(key+" "+books.get(key));}System.out.println("---------");Set params = props.keySet();for(Object obj:params ){System.out.println(obj+" : "+props.getProperty(obj.toString()));}}public void setCitys(List<String> citys) {this.citys = citys;}public void setBooks(Map<Integer, String> books) {this.books = books;}}
配置文件中配置
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"><beans><bean id="userdao" class="com.dao.impl.HibernateUserDAO"></bean><!-- setter方式注入 --><bean id="useraction" class="com.action.UserAction"> <property name="userDao" ref="userdao"> </property></bean><!-- 构造器方式注入 --><bean id="useraction1" class="com.action.UserAction1"> <constructor-arg index="0" ref="userdao"/></bean><!-- 各种类型值注入的写法 --><bean id="messagebean" class="com.bean.MessageBean"><property name="props"><props><prop key="url">http://www.tom.com</prop><prop key="username">zhangsan</prop><prop key="password">123456789</prop></props></property><property name="books"><map><entry key="10" value="CoreJava"></entry><entry key="11" value="JavaWeb"></entry><entry key="12" value="SSH2"></entry></map></property><property name="friends"><set><value>张三</value><value>李四</value><value>王五</value></set></property><property name="citys"><list><value>北京</value><value>上海</value><value>深圳</value></list></property><property name="username"><value>root</value></property><property name="password"><value>1234</value></property><property name="size"><value>15</value></property></bean></beans>
代码中调用
String[] configs = {"applicationContext.xml"};ApplicationContext ac =new ClassPathXmlApplicationContext(configs);MessageBean msgBean = (MessageBean)ac.getBean("messagebean");msgBean.show();
- spring 配置文件中如何注入map list set等类型
- spring 3配置文件中如何注入map list set等类型
- Spring中注入List Set Map Properties的配置文件
- 在spring 中如何注入map,set,list,property等参数
- spring如何注入List,Set,Map对象
- (3) spring注入Properties,List,Set,Map
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- spring注入list set map
- Spring注入容器类型List、Map、Properties、Set
- spring 配置文件 list map set
- Spring Set注入:基本类型、List、Map、Set、Array、Date类型注入
- Spring:Set注入:基本类型、List、Map、Set、Array、Date类型注入...
- 父类指针可以指向子类反之则不行
- hdu 4605(离线 + dfs + 树状数组(好题))
- 浅谈怎样一个人把网站发展起来
- 水晶报表设置数据源位置
- MTK Android4.0.3 ICS 添加缅甸语Myanmar
- spring 3配置文件中如何注入map list set等类型
- 用ASIHttpRequest通过post请求给java服务器上传的代码(不会出现乱码)
- 解决关于安装Altium Designer6.9之后打开PCB文档电脑蓝屏的问题
- div 的scrollTop增长问题
- 【相亲时如何判断一个男生的好坏】
- dm368ipnc 重写架构中的swosd 实现中文osd
- 布隆过滤器原理
- Gxt 3.0 修改文本框 为空的 提示
- Mysql缓存命中率