<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之旅 廣告
                ## 屬性的依賴注入 spring在通過IOC創建這個對象的時候,如果這個對象還有屬性,就一并賦值.ID是在IOC的基礎上進行對象的屬性注入的.也就是說先有IOC,才能DI. ~~~ <bean id="user" class="com.like.serviceImpl.User "> <property name="name" value="jack"/> <property name="age" value="20"/> </bean> ~~~ ## ref屬性 ~~~ <bean id="car" class="com.like.domain.Car"> <property name="name" value="蘭博基尼"/> <property name="price" value="10000"/> </bean> <bean id="user" class="com.like.domain.User"> <property name="name" value="jack"/> <property name="age" value="20"/> <property name="car" ref="car"/> //ref針對的是對象類型 </bean> ~~~ ~~~ public class User { private String name; private Integer age; private Car car; //有Car的對象 @Override public String toString() { return "User{" + "name='" + name + '\'' + ", age=" + age + ", car=" + car + '}'; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public Car getCar() { return car; } public void setCar(Car car) { this.car = car; } } ~~~ 結果: ``` User{name='jack', age=20, car=Car{name='蘭博基尼', price=10000.0}} ``` ## 構造器依賴注入 條件是,必須有有參構造器. 配置: ~~~ <bean id="user" class="com.like.User"> <constructor-arg name="name" value="jack"/> //value針對的是基本類型和String類型 <constructor-arg name="age" value="20"/> </bean> ~~~ bean: ~~~ public class User { private String name; private Integer age; public User() { } public User(String name, Integer age) { this.name = name; this.age = age; } @Override public String toString() { return "User{" + "name='" + name + '\'' + ", age=" + age + '}'; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } } ~~~ ## P名稱空間屬性注入 條件:在配置文件中有P的名稱空間,底層還是用的set方式. ~~~ xmlns:p="http://www.springframework.org/schema/p" //:后面的 p 是別名 ~~~ ~~~ <bean id="car" class="com.like.domain.Car"> <property name="name" value="蘭博基尼"/> <property name="price" value="10000"/> </bean> <bean id="user" class="com.like.domain.User" p:name="jack" p:age="20" p:car-ref="car"></bean> ~~~ ## 復雜方式注入 ~~~ public class CollBean { private String[] strings; private List list; private Map map; private Properties properties; @Override public String toString() { return "CollBean{" + "strings=" + Arrays.toString(strings) + ", list=" + list + ", map=" + map + ", properties=" + properties + '}'; } public String[] getStrings() { return strings; } public void setStrings(String[] strings) { this.strings = strings; } public List getList() { return list; } public void setList(List list) { this.list = list; } public Map getMap() { return map; } public void setMap(Map map) { this.map = map; } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } } ~~~ ~~~ <bean id="car" class="com.like.domain.Car"> <property name="name" value="蘭博基尼"/> <property name="price" value="200"/> </bean> <bean id="collBean" class="com.like.domain.CollBean"> <property name="strings"> <list> <value>a</value> <value>b</value> <value>c</value> </list> </property> <property name="list"> <list> <value>1</value> <value>2</value> <ref bean="car"/> </list> </property> <property name="map"> <map> <entry key="key1" value="a"/> <entry key="key2" value="b"/> <entry key="key2" value-ref="car"/> </map> </property> <property name="properties"> <props> <prop key="hibernate.username">root</prop> <prop key="hibernate.password">123</prop> </props> </property> </bean> ~~~ 結果: ``` CollBean{strings=[a, b, c], list=[1, 2, Car{name='蘭博基尼', price=200.0}], map={key1=a, key2=Car{name='蘭博基尼', price=200.0}}, properties={hibernate.password=123, hibernate.username=root}} ```
                  <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>

                              哎呀哎呀视频在线观看