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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                案例代碼:https://gitee.com/flymini/codes01/tree/master/spring_/com-learn-spring03 *** 在 IoC 容器中注入屬性一共有下面 3 種方式。 ``` 1. Setter方法注入,需要提供屬性的Setter方法。 2. 構造器注入,需要提供對應的構造器。 3. 命名空間注入,需要提供屬性的Setter方法。 ``` **1. 創建一個實體類** ```java @Data public class Student { private String name; private Integer age; private Integer total; private String idCard; public Student(Integer age, Integer total) { this.age = age; this.total = total; } } ``` **2. 在 IoC 容器中注入屬性** ```xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:utils="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd"> <!-- p:attrName 是按照命名空間注入 --> <bean id="student" class="com.learn.spring03.pojo.Student" p:idCard="17511222222"> <!-- property是通過Setter注入 --> <property name="name" value="張三"/> <!-- constructor-arg是通過構造器注入 name:按照構造器中參數名注入; index:按照構造器中參數位置注入,從左到右,索引從0開始 --> <constructor-arg name="age" value="25"/> <constructor-arg index="1" value="175"/> </bean> </beans> ``` **3. 測試** ```java public class StudentTest { /** * 獲取 IoC 容器 */ private final ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContentext.xml"); @Test public void testStudent() { Student student = context.getBean("student", Student.class); //Student(name=張三, age=25, total=175, idCard=17511222222) System.out.println(student); } } ```
                  <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>

                              哎呀哎呀视频在线观看