网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > J2EE/J2ME
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.J2EE架构的6个最佳实践.
.MIDP 1.0 HttpConnection类的rob.
.使用EJB3.0简化企业级Java开发一.
.在Spring中使用JDBC.
.JNDI 常见问题.
.RMS概念解析与使用指南.
.WeblogicEJB学习笔记一.
.精通Hibernate映射继承关系之二.
.查询手机支持的多媒体类型和协议.
.精通Micro3D v3基础技术.
.Canvas和Media实现钢琴效果.
.一个简单的CustomItem使用案例.
.windy‘s j2ee1.4 tutorial (chi.
.开源密码管理软件.
.简单封装MIDP RMS操作.
.搭建OTA下载服务器.
.Axis2 中的工具wsdl2Java 的使用.
.MIDP图形用户界面结构分析.
.j2ee技术简单介绍.
.多重提交处理(一).

在Spring中配置Collection

发表日期:2007-12-23


///////////////////////////////////////////////////////////////////////////////////////
//File: beans.XML

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <!-- Oracle bean used for a few examples -->
    <bean id="oracle" name="wiseworm" class="BookwormOracle"/>

    <!-- collection injection samples -->
    <bean id="injectCollection" class="CollectionInjection">
        <property name="map">
            <map>
                <entry key="someValue">
                    <value>Hello World!</value>
                </entry>
                <entry key="someBean">
                    <ref local="oracle"/>
                </entry>
            </map>
        </property>
        <property name="props">
            <props>
                <prop key="firstName"> Rob </prop>
                <prop key="secondName"> Harrop </prop>
            </props>
        </property>
        <property name="set">
            <set>
                <value>Hello World!</value>
                <ref local="oracle"/>
            </set>
        </property>
        <property name="list">
            <list>
                <value>Hello World!</value>
                <ref local="oracle"/>
            </list>
        </property>
    </bean>
</beans>

///////////////////////////////////////////////////////////////////////////////////////

public interface Oracle {

    public String defineMeaningOfLife();
}

///////////////////////////////////////////////////////////////////////////////////////
public class Encyclopedia {

}



///////////////////////////////////////////////////////////////////////////////////////

public class BookwormOracle implements Oracle {

    private Encyclopedia enc;

    public void setEncyclopedia(Encyclopedia enc) {
        this.enc = enc;
    }

    public String defineMeaningOfLife() {
        return "Encyclopedia's are a waste of money - use the Internet";
    }

}

///////////////////////////////////////////////////////////////////////////////////////
import Java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class CollectionInjection {

    private Map map;

    private Properties props;

    private Set set;

    private List list;

    public static void main(String[] args) {
        BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
                "build/beans.xml"));

        CollectionInjection instance = (CollectionInjection) factory.getBean("injectCollection");
        instance.displayInfo();
    }

    public void setList(List list) {
        this.list = list;
    }

    public void setSet(Set set) {
        this.set = set;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    public void setProps(Properties props) {
        this.props = props;
    }

    public void displayInfo() {

        // display the Map
        Iterator i = map.keySet().iterator();

        System.out.println("Map contents:\n");
        while (i.hasNext()) {
            Object key = i.next();
            System.out.println("Key: " + key + " - Value: " + map.get(key));
        }

        // display the properties
        i = props.keySet().iterator();
        System.out.println("\nProperties contents:\n");
        while (i.hasNext()) {
            String key = i.next().toString();
            System.out.println("Key: " + key + " - Value: "
                    + props.getProperty(key));
        }

        // display the set
        i = set.iterator();
        System.out.println("\nSet contents:\n");
        while (i.hasNext()) {
            System.out.println("Value: " + i.next());
        }

        // display the list
        i = list.iterator();
        System.out.println("\nList contents:\n");
        while (i.hasNext()) {
            System.out.println("Value: " + i.next());
        }
    }
}

(出处:)


上一篇:连接MySQL并执行Update 人气:894
下一篇:在Spring中配置非Singleton 人气:1110
浏览全部J2EE/J2ME的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐