<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ~~~ <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> <!--把對象的創建交給spring來管理--> <!--spring中的依賴注入 依賴注入: Dependency Injection IoC的作用: 降低程序間的耦合(依賴關系) 依賴關系的管理: 以后都交給spring來維護 在當前類需要用到其他類的對象,由spring為我們提供,我們只需要在配置文件說明 依賴關系的維護: 就稱之為依賴注入 依賴注入: 能注入的數據:有三類 基本數據,String 其他bean類型(在配置文件中或者注解配置過的bean) 復雜類型/集合類型 注入的方式: 有三種 第一種:使用構造函數提供 第二種:使用set方法提供 第三種:使用注解提供 --> <!-- 第一種方式,構造函數注入 使用標簽:constructor-arg 標簽出現的位置: bean標簽的內部 標簽中的屬性: type:用來指定要注入的數據的數據類型,該數據類型也是構造函數中某個或某些參數的類型 index: 構造函數按索引位置來賦值,索引的位置是從0開始 name: 按名稱來給構造函數參數賦值 value: 指定構造函數參數的值,限于基本類型和String類型 ref: 用于指定其他的bean類型數據.它指的就是在spring的IoC核心容器中出現過的bean對象 優勢: 在獲取bean對象時,注入數據是必須的操作,否則對象無法創建成功 弊端: 改變了bean對象的實例化方式,使我們在在創建對象時,如果用不到這些數據,也必須提供. --> <bean id="accountService6" class="com.itheima.service.impl.AccountServiceImpl6"> <constructor-arg name="age" type="java.lang.Integer" value="20"></constructor-arg> <constructor-arg name="name" value="test"></constructor-arg> <constructor-arg name="birthDate" ref="now"></constructor-arg> </bean> <!-- 配置一個日期對象--> <bean id="now" class="java.util.Date"></bean> <!-- 第二種方式 set方法注入 常用的方式 涉及的標簽: property 出現的位置: bean標簽的內部 標簽的屬性: name: 用于指定注入時所調用的set方法名稱 value: 用于提供基本類型和String類型的數據 ref: 用于指定其他的bean類型數據.它指的就是在spring的IoC核心容器中出現過的bean對象 優勢: 創建對象時沒有明確的限制,可以直接使用默認構造函數 弊端: 如果有某個成員必須有值,則獲取對象是有可能獲取不到值,set方法沒有執行. --> <bean id="accountService7" class="com.itheima.service.impl.AccountServiceImpl7"> <property name="name" value="喬峰"></property> <property name="age" value="28"></property> <property name="birthDate" ref="now"></property> </bean> </beans> ~~~ ***** ~~~ package com.itheima.service.impl; import com.itheima.service.IAccountService; import java.util.Date; /** * @author: hcf * @qq: 46914685 * @email: 46914685@qq.com */ /** * 賬戶的業務層實現類 */ public class AccountServiceImpl7 implements IAccountService { //如果是經常變化的數據,并不適用于注入的方式 private String name; private Integer age; private Date birthDate; public void setName(String name) { this.name = name; } public void setAge(Integer age) { this.age = age; } public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } public void saveAccount() { System.out.println("service中的saveAccount方法執行了! " + name + "," + age + "," + birthDate); } } ~~~ ***** ~~~ /** * 第二種方式 set方法注入 */ @Test public void testDI2(){ ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("bean3.xml"); IAccountService as = (IAccountService) ac.getBean("accountService7"); as.saveAccount(); } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看