<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 笑口常開、財源滾滾來! 閱讀(1608) 評論(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无码专区蜜桃 | 亚洲色婷婷六月亚洲婷婷6月 | 国产精品亚洲а∨无码播放麻豆| 免费精品国偷自产在线在线| 亚洲视频一区在线观看| 日韩精品人妻系列无码专区免费| 亚洲色WWW成人永久网址| 99在线免费观看| 真人无码作爱免费视频| 国产精品深夜福利免费观看| 亚洲精品中文字幕无码A片老| 在线免费观看h片| 国产成人无码综合亚洲日韩| 无码人妻精品中文字幕免费 | 久久精品人成免费| 免费人成激情视频| 久久精品亚洲一区二区三区浴池| 日韩精品无码专区免费播放| 亚洲午夜在线播放| 久久香蕉国产线看免费| 久久亚洲AV成人无码软件| 亚洲天堂免费在线| 国产在亚洲线视频观看| 在线观看午夜亚洲一区| 亚洲一区二区三区免费视频| 亚洲性色AV日韩在线观看| 日批日出水久久亚洲精品tv| 免费看一区二区三区四区| 91亚洲导航深夜福利| 香蕉视频在线观看免费国产婷婷| 国产亚洲精品成人久久网站| 亚洲中文字幕无码中文字在线| 亚洲a一级免费视频| 亚洲精品无码av中文字幕| 久久99亚洲综合精品首页| 99久久人妻精品免费一区| 亚洲AV无码一区二区三区电影| 免费羞羞视频网站| 怡红院免费的全部视频| 亚洲一区二区三区乱码在线欧洲| 亚洲国产V高清在线观看|