<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    即興的靈感

    思維是一種藝術(shù); 藝術(shù)需要靈感。

    博客好友

    最新評(píng)論

    Spring筆記之二(Collection Injection)

    通過(guò)<list/>,<set/>,<map/>以及<props/>元素定義和設(shè)置與java collection類(lèi)型對(duì)應(yīng)的List,Set,Map,Rproperties的值。
    ?1?import ?java.util.Iterator;
    ?2?import
    ?java.util.List;
    ?3?import
    ?java.util.Map;
    ?4?import
    ?java.util.Properties;
    ?5?import
    ?java.util.Set;
    ?6?

    ?7?import ?org.springframework.beans.factory.BeanFactory;
    ?8?import
    ?org.springframework.beans.factory.xml.XmlBeanFactory;
    ?9?import
    ?org.springframework.core.io.FileSystemResource;
    10?

    11?public?class ?CollectionInjection?{
    12?

    13?????private ?Map?map;
    14?

    15?????private ?Properties?props;
    16?

    17?????private ?Set?set;
    18?

    19?????private ?List?list;
    20?

    21?????public?static?void ?main(String[]?args)?{
    22?????????BeanFactory?factory?=?new?XmlBeanFactory(new
    ?FileSystemResource(
    23?????????????????"src/applicationContext.xml"
    ));
    24?

    25?????????CollectionInjection?instance?= ?(CollectionInjection)
    ????????????????????????????????????????? factory.getBean(
    " injectCollection "
    );
    26?
    ????????instance.displayInfo();
    27?
    ????}
    28?

    29?????public?void ?setList(List?list)?{
    30?????????this.list?=
    ?list;
    31?
    ????}
    32?

    33?????public?void ?setSet(Set?set)?{
    34?????????this.set?=
    ?set;
    35?
    ????}
    36?

    37?????public?void ?setMap(Map?map)?{
    38?????????this.map?=
    ?map;
    39?
    ????}
    40?

    41?????public?void ?setProps(Properties?props)?{
    42?????????this.props?=
    ?props;
    43?
    ????}
    44?

    45?????public?void ?displayInfo()?{
    46?

    47?????????//?display?the?Map
    48?????????Iterator?i?= ?map.keySet().iterator();
    49?

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

    56?????????//?display?the?properties
    57?????????i?= ?props.keySet().iterator();
    58?????????System.out.println("\nProperties?contents:\n"
    );
    59?????????while
    ?(i.hasNext())?{
    60?????????????String?key?=
    ?i.next().toString();
    61?????????????System.out.println("Key:?"?+?key?+?"?-?Value:?"

    62?????????????????????+ ?props.getProperty(key));
    63?
    ????????}
    64?

    65?????????//?display?the?set
    66?????????i?= ?set.iterator();
    67?????????System.out.println("\nSet?contents:\n"
    );
    68?????????while
    ?(i.hasNext())?{
    69?????????????System.out.println("Value:?"?+
    ?i.next());
    70?
    ????????}
    71?

    72?????????//?display?the?list
    73?????????i?= ?list.iterator();
    74?????????System.out.println("\nList?contents:\n"
    );
    75?????????while
    ?(i.hasNext())?{
    76?????????????System.out.println("Value:?"?+
    ?i.next());
    77?
    ????????}
    78?
    ????}
    79?
    }


    1?public?class ?RefBean?{
    2?????public
    ?String?toString()
    3?
    ????{
    4?????????return?"refBean"
    ;
    5?
    ????}
    6?}

    ?1?<?xml?version="1.0"?encoding="UTF-8"?>
    ?2?<! DOCTYPE?beans?PUBLIC?"-//SPRING//DTD?BEAN//EN"
    ??? "http://www.springframework.org/dtd/spring-beans.dtd"
    >

    ?3?<beans>
    ?4? ????
    ?5?????<!--?oracle?bean?used?for?a?few?examples?-->

    ?6?????<bean?id="refBean"?name="refB"?class="RefBean"/>
    ?7?
    ?8?????<!--?collection?injection?samples?-->
    ?9?????<bean?id="injectCollection"?class="CollectionInjection">
    10?????????<property?name="map">
    11?????????????<map>
    12?????????????????<entry?key="nameValue">
    13?????????????????????<value>gzhb_improviser</value>
    14?????????????????</entry>
    15?????????????????<entry?key="refBeanValue">
    16?????????????????????<ref?local="refBean"/>
    17?????????????????</entry>
    18?????????????</map>
    19?????????</property>
    20?????????<property?name="props">
    21?????????????<props>
    22?????????????????<prop?key="firstName">?gzhb?</prop>
    23?????????????????<prop?key="secondName">?improviser?</prop>
    24?????????????</props>
    25?????????</property>
    26?????????<property?name="set">
    27?????????????<set>
    28?????????????????<value>gzhb</value>
    29?????????????????<ref?local="refBean"/>
    30?????????????</set>
    31?????????</property>
    32?????????<property?name="list">
    33?????????????<list>
    34?????????????????<value>improviser</value>
    35?????????????????<ref?local="refBean"/>
    36?????????????</list>
    37?????????</property>
    38?????</bean>
    39?</beans


    運(yùn)行結(jié)果:
    Map contents:

    Key: nameValue - Value: gzhb_improviser
    Key: refBeanValue - Value: refBean

    Properties contents:

    Key: secondName - Value: improviser
    Key: firstName - Value: gzhb

    Set contents:

    Value: gzhb
    Value: refBean

    List contents:

    Value: improviser
    Value: refBean

    注意map的key或value值,或set的value值不能一下元素:
    bean,ref,idref,list,set,map,props,vaues,null

    集合合并
    Spring2.0支持集合合并,子類(lèi)Bean實(shí)例可以合并和重寫(xiě)抽象父類(lèi)Bean實(shí)例的集合屬性。

    ???1.?? < beans > ??
    ???2.?
    < bean? id ="parent" ?abstract ="true" ?class ="example.ComplexObject" >
    ??
    ???3.?
    < property? name ="pro" >
    ??
    ???4.?
    < props >
    ??
    ???5.?
    < prop? key ="pro1" > pro1 </ prop >
    ??
    ???6.?
    < prop? key ="pro3" >pro3 </ prop >
    ??
    ???7.?
    </ props >
    ??
    ???8.?
    </ property >
    ??
    ???9.?
    </ bean >
    ??
    ??10.?
    < bean? id ="child" ?parent ="parent" >
    ??
    ??11.?
    < property? name ="pro" >
    ??
    ??12.?
    <!-- ?the?merge?is?specified?on?the?*child*?collection?definition? -->
    ??
    ??13.?
    < props? merge ="true" >
    ??
    ??14.?
    < prop? key ="pro2" > pro2 </ prop >
    ??
    ??15.?
    < prop? key ="pro3" > pro3 </ prop >
    ??
    ??16.?
    </ props >
    ??
    ??17.?
    </ property >
    ??
    ??18.?
    </ bean >
    ??
    ??19.?
    < beans >
    ??

    通過(guò)合并,子bean的pro3值覆蓋父bean的值,不同集合類(lèi)型不能合并,子bean中的merge必須定義,否則出現(xiàn)異常。


    ?
    鳳凰涅槃/浴火重生/馬不停蹄/只爭(zhēng)朝夕
    ???? 隱姓埋名/低調(diào)華麗/簡(jiǎn)單生活/完美人生

    posted on 2007-09-24 10:23 poetguo 閱讀(1690) 評(píng)論(2)  編輯  收藏 所屬分類(lèi): Spring

    評(píng)論

    # re: Spring筆記之二(Collection Injection) 2007-09-24 11:07 千里冰封

    我還是覺(jué)得SPRING的XML配置多了一些,EJB3.0就好多了  回復(fù)  更多評(píng)論   

    # re: Spring筆記之二(Collection Injection) 2007-09-24 12:09 improviser

    以后有時(shí)間也研究研究EJB3.0,到時(shí)再請(qǐng)教,先謝啦 :)  回復(fù)  更多評(píng)論   

    主站蜘蛛池模板: 免费91麻豆精品国产自产在线观看 | 中文字幕乱码一区二区免费| 在线免费观看中文字幕| 亚洲国产综合自在线另类| 91高清免费国产自产拍2021| 亚洲AV无码日韩AV无码导航| 久久国产美女免费观看精品| 亚洲性久久久影院| 国产成人人综合亚洲欧美丁香花| 在线视频亚洲一区| 在线观看91精品国产不卡免费| 四虎免费久久影院| 亚洲av永久无码精品网址| 免费精品国产自产拍在| 国产成人亚洲综合一区| 欧洲精品免费一区二区三区| 久久精品熟女亚洲av麻豆| 亚洲成A∨人片天堂网无码| 一个人看的免费视频www在线高清动漫| 无码国产精品一区二区免费模式 | 毛片免费观看的视频在线| 亚洲人成日本在线观看| 国产人在线成免费视频| 午夜亚洲WWW湿好爽| 中文字幕亚洲天堂| 一区二区三区观看免费中文视频在线播放| 四色在线精品免费观看| 国产亚洲视频在线观看网址| 国产精品亚洲二区在线观看| 久久国产乱子免费精品| 亚洲日产2021三区在线| 日韩高清免费在线观看| 精品乱子伦一区二区三区高清免费播放| 免费v片在线观看视频网站| 亚洲人成网男女大片在线播放 | 亚洲日本人成中文字幕| 亚洲美日韩Av中文字幕无码久久久妻妇| 亚洲欧洲尹人香蕉综合| 在线日韩av永久免费观看| eeuss草民免费| 亚洲无圣光一区二区|