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

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

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

    千山鳥飛絕 萬徑人蹤滅
    勤練內(nèi)功,不斷實踐招數(shù)。爭取早日成為武林高手

    public interface IPersonService {

     public abstract void Save();
     public Set<String> getSets() ;
     public List<String> getLists() ;
     public Properties getProperties() ;
     public Map<String, String> getMaps() ;

    }



    public class PersonServiceBean implements IPersonService {

     private IPersonDao iPersonDao;
     private Set<String> sets=new HashSet<String>();
     private List<String> lists=new ArrayList<String>();
     private Properties properties=new Properties();
     private Map<String,String> maps=new HashMap<String,String>();
     
     public PersonServiceBean(IPersonDao personDao, String name) {
      
      iPersonDao = personDao;
      this.name = name;
     }
     public void Save(){
      System.out.println(name);//輸出name
      iPersonDao.add();
     }

     private String name;
     
     public String getName() {
      return name;
     }

     public void setName(String name) {
      this.name = name;
     }

     public Map<String, String> getMaps() {
      return maps;
     }

     public void setMaps(Map<String, String> maps) {
      this.maps = maps;
     }

     public Properties getProperties() {
      return properties;
     }

     public void setProperties(Properties properties) {
      this.properties = properties;
     }

     public Set<String> getSets() {
      return sets;
     }

     public void setSets(Set<String> sets) {
      this.sets = sets;
     }

     public IPersonDao getIPersonDao() {
      return iPersonDao;
     }

     public void setIPersonDao(IPersonDao personDao) {
      iPersonDao = personDao;
     }

     
     public List<String> getLists() {
      return lists;
     }

     public void setLists(List<String> lists) {
      this.lists = lists;
     }
    }



    測試類:

    public class SpringTest {

     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
     }
     @Test
     public void instanceSpring() {
      ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
        "beans.xml");
      // ItcastClassPathXMLApplicationContext ctx=new
      // ItcastClassPathXMLApplicationContext("beans.xml");
      //  
      IPersonService ipersonService = (IPersonService) ctx
        .getBean("personService");
      //集合對象的遍歷
      System.out.println("===========set==================");
      for (String value : ipersonService.getSets()) {
       
       System.out.println(value);
      }
      // ipersonService.Save();
      // ctx.close();
      // ctx.registerShutdownHook();
      System.out.println("===========List=================");
      for(String value:ipersonService.getLists()){
       
       System.out.println(value);
      }
      
      System.out.println("=========properties===============");
      for(Object value:ipersonService.getProperties().keySet()){
       System.out.println(value);
      }
      System.out.println("================maps==================");
      for(Object value:ipersonService.getMaps().keySet()){
       System.out.println(value);
      }
      //調(diào)用PersonServiceBean的sava方法,輸出結(jié)果
      ipersonService.Save();
      
     }
    }



    <beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
     <bean id="personService"
      class="cn.itcast.service.impl.PersonServiceBean">
      <property name="IPersonDao" ref="personDaoBean"></property>

      <constructor-arg index="0" ref="personDaoBean"
       type="cn.itcast.dao.IPersonDao" />
      <constructor-arg index="1" type="java.lang.String"
       value="傳智博客">
      </constructor-arg>

      <property name="sets">
       <set>
        <value>set1</value>
        <value>set2</value>
        <value>set3</value>
       </set>
      </property>

      <property name="lists">
       <list>
        <value>list1</value>
        <value>list2</value>
        <value>list3</value>
       </list>
      </property>

      <property name="properties">
       <props>
        <prop key="properties1">property1</prop>
        <prop key="properties2">property2</prop>
        <prop key="properties3">property3</prop>
       </props>
      </property>

      <property name="maps">
       <map>
        <entry key="key1" value="keyFirst"></entry>
        <entry key="key2" value="keySecond"></entry>
        <entry key="key3" value="keyThird"></entry>
       </map>
      </property>
     </bean>
     <bean id="personDaoBean" class="cn.itcast.dao.impl.PersonDaoBean"></bean>


     <!--
      <bean id="anotherPersonServiceBean"
      class="cn.itcast.service.impl.AnotherPersonServiceBean" >
      </bean>
     -->
    </beans>


    public class PersonDaoBean implements IPersonDao {
     public void add(){
      System.out.println("這是personDaoBean的Add()方法");
     }
    }



    輸出:


    ===========set==================
    set1
    set2
    set3
    ===========List=================
    list1
    list2
    list3
    =========properties===============
    properties3
    properties2
    properties1
    ================maps==================
    key1
    key2
    key3
    傳智博客
    這是personDaoBean的Add()方法

    posted on 2009-08-27 18:19 笑口常開、財源滾滾來! 閱讀(1607) 評論(3)  編輯  收藏 所屬分類: spring學習
    Comments
    • # re: 集合對象注入&&通過構(gòu)造函數(shù)注入
      雨中滴
      Posted @ 2009-08-28 14:37
      真的很無聊- -  回復(fù)  更多評論   
    • # re: 集合對象注入&&通過構(gòu)造函數(shù)注入
      chencx
      Posted @ 2009-08-29 16:43
      無聊…的飄過……  回復(fù)  更多評論   
    • # re: 集合對象注入&&通過構(gòu)造函數(shù)注入
      game
      Posted @ 2016-07-19 09:54
      這哪是通過構(gòu)造函數(shù)注入?明明就是通過setter注入的。  回復(fù)  更多評論   
     
    主站蜘蛛池模板: 亚洲一区二区三区在线| 亚洲色精品vr一区二区三区| 亚洲黄色免费网站| 久久大香香蕉国产免费网站| 亚洲综合中文字幕无线码| 91制片厂制作传媒免费版樱花| 亚洲日产韩国一二三四区| 中文字幕在线免费播放| 国产精品亚洲а∨无码播放| 成人国产精品免费视频| 亚洲AV成人无码久久精品老人| 国产精品久久亚洲不卡动漫| 114一级毛片免费| 亚洲综合av一区二区三区| 成人免费无码大片A毛片抽搐色欲 成人免费无码大片a毛片 | 最近免费字幕中文大全视频| 久久久久久久亚洲Av无码 | 亚洲av无码无线在线观看| 国产成人精品免费视频软件| 偷自拍亚洲视频在线观看| 国产成人精品曰本亚洲79ren| 两个人看的www高清免费观看| 大学生a级毛片免费观看| 国产成人亚洲精品电影| 亚洲欧洲精品无码AV| 最近免费中文字幕大全免费版视频 | 亚洲乱码中文字幕手机在线 | 亚洲视频一区二区三区四区| 成年美女黄网站色大免费视频| 午夜亚洲国产精品福利| 亚洲人色婷婷成人网站在线观看 | 免费看美女被靠到爽的视频| 美女视频黄a视频全免费网站一区| 亚洲愉拍99热成人精品热久久 | 一个人免费观看日本www视频 | 99热免费在线观看| 亚洲精华国产精华精华液好用 | 国产精品亚洲一区二区三区在线观看 | 国产天堂亚洲国产碰碰| 亚洲AV美女一区二区三区| 妞干网免费观看视频|