<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ~~~ <?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> </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 AccountServiceImpl6 implements IAccountService { //如果是經常變化的數據,并不適用于注入的方式 private String name; private Integer age; private Date birthDate; public AccountServiceImpl6(String name, Integer age, Date birthDate) { this.name = name; this.age = age; this.birthDate = birthDate; } public void saveAccount() { System.out.println("service中的saveAccount方法執行了!66666 " + name + "," + age + "," + birthDate); } } ~~~ ***** ~~~ /** * 測試構造函數注入 */ @Test public void testDI(){ //1.獲取核心容器對象 ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("bean3.xml"); IAccountService as = (IAccountService) ac.getBean("accountService6"); 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>

                              哎呀哎呀视频在线观看