Leetcode刷題之一口氣看完01揹包和完全揹包的一維陣列版以及二維陣列版
阿新 • • 發佈:2022-04-17
一,構造器注入
上一篇已經寫過,不做贅述
二,set方式注入(重點)
依賴注入:Set注入!
依賴:bean物件的建立依賴容器
注入:bean物件所有的屬性,由容器注入
環境搭建
1.複雜型別
2.真實測試物件
3.beans.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="address" class="com.luo.pojo.Address">
<property name="address" value="廣州"/>
</bean>
<bean id="student" class="com.luo.pojo.Student">
<!--普通注入-->
<property name="name" value="小磊"/>
<!--Bean注入-->
<property name="address" ref="address"/>
<!--陣列注入-->
<property name="books">
<array>
<value>紅樓夢</value>
<value>西遊記</value>
<value>水滸傳</value>
<value>三國演義</value>
</array>
</property>
<!--List-->
<property name="hobbys">
<list>
<value>聽歌</value>
<value>敲程式碼</value>
<value>看電影</value>
</list>
</property>
<!--Map-->
<property name="card">
<map>
<entry key="身份證" value="4561564897481561351"/>
<entry key="銀行卡" value="4684894131315341864"/>
</map>
</property>
<!--Set-->
<property name="games">
<set>
<value>LOL</value>
<value>BOB</value>
<value>COC</value>
</set>
</property>
<!--null-->
<property name="wife">
<null/>
</property>
<!--properties-->
<property name="info">
<props>
<prop key="學號">1812230104</prop>
<prop key="性別">男</prop>
<prop key="username">root</prop>
<prop key="password">123456</prop>
</props>
</property>
</bean>
</beans>
4.測試
三,拓展方式注入
p名稱空間注入和c名稱空間注入
p名稱空間和c名稱空間不能直接使用,需要匯入xml約束
四,bean的作用域
singleton
prototype
request
session
application
websocket
1.單例模式(spring預設機制)
singleton
2.原型模式:每次從容其中get的時候,會生成一個新的物件
prototype
測試
reques,session,application這些在web開發中使用到