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

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

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

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

    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);
      }
      //調用PersonServiceBean的sava方法,輸出結果
      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 笑口常開、財源滾滾來! 閱讀(1602) 評論(3)  編輯  收藏 所屬分類: spring學習
    Comments
    • # re: 集合對象注入&&通過構造函數注入
      雨中滴
      Posted @ 2009-08-28 14:37
      真的很無聊- -  回復  更多評論   
    • # re: 集合對象注入&&通過構造函數注入
      chencx
      Posted @ 2009-08-29 16:43
      無聊…的飄過……  回復  更多評論   
    • # re: 集合對象注入&&通過構造函數注入
      game
      Posted @ 2016-07-19 09:54
      這哪是通過構造函數注入?明明就是通過setter注入的。  回復  更多評論   
     
    主站蜘蛛池模板: 亚洲一级免费毛片| 亚洲AV人无码综合在线观看| www免费黄色网| 免费永久看黄在线观看app| 亚洲欧美成人综合久久久| 青柠影视在线观看免费高清| 亚洲色偷拍区另类无码专区| 三年片在线观看免费观看大全中国| 午夜国产大片免费观看| 男女交性无遮挡免费视频| 亚洲宅男天堂在线观看无病毒| 99在线热播精品免费99热| 亚洲AV乱码一区二区三区林ゆな| 久久久久久毛片免费播放| 亚洲三级视频在线| 日本免费的一级v一片| 成人精品综合免费视频| 国产av无码专区亚洲av果冻传媒 | 日韩免费一区二区三区在线播放| 永久免费看bbb| 成人婷婷网色偷偷亚洲男人的天堂| 免费a级毛片永久免费| 亚洲精品黄色视频在线观看免费资源 | 久久亚洲精品成人| 最近2018中文字幕免费视频| 精品亚洲国产成人| 亚洲成?v人片天堂网无码| 免费无码又爽又刺激高潮软件| 亚洲综合激情九月婷婷 | 两性色午夜视频免费播放| 亚洲精品美女久久久久9999| 在线播放免费人成视频在线观看| 污网站免费在线观看| 亚洲国产女人aaa毛片在线| 精品久久久久国产免费| 成人嫩草影院免费观看| 亚洲视频中文字幕在线| 国产国产人免费人成免费视频| 国产亚洲精品成人AA片| 亚洲精品视频在线观看你懂的| 男男gay做爽爽免费视频|