spring如何使用命名空間p簡化bean的配置
這篇文章主要介紹了spring如何使用命名空間p簡化bean的配置,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
一般情況下,我們是這么配置bean的:
<bean id="car1" class="com.gong.spring.beans.Car"> <property name="name" value="baoma"></property> </bean> <bean id="car2" class="com.gong.spring.beans.Car"> <property name="name" value="benchi"></property> </bean> <bean id="car3" class="com.gong.spring.beans.Car"> <property name="name" value="binli"></property> </bean> <bean id="student" class="com.gong.spring.beans.Student"> <property name="name" value="tom"></property> <property name="age" value="12"></property> <property name="score" value="98.00"></property> <property name="cars" ref="cars"> </property> </bean> <util:list id="cars"> <ref bean="car1"/> <ref bean="car2"/> <ref bean="car3"/> </util:list>
說明:cars是公用的集合Bean,Student里有name、age、score以及類型為List<Car>的car屬性。
在引入了命名空間之后,我們就可以這么進(jìn)行配置了:
<bean id="car1" class="com.gong.spring.beans.Car" p:name="baoma"></bean> <bean id="car2" class="com.gong.spring.beans.Car" p:name="benchi"></bean> <bean id="car3" class="com.gong.spring.beans.Car" p:name="binli"></bean> <bean id="student" class="com.gong.spring.beans.Student" p:name="tom" p:age="12" p:score="98.00" p:cars-ref="cars"></bean> <util:list id="cars"> <ref bean="car1"/> <ref bean="car2"/> <ref bean="car3"/> </util:list>
相較于原來的,代碼簡潔了很多。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:如何實(shí)現(xiàn)java Iterator迭代器功能
欄 目:Java
本文標(biāo)題:spring如何使用命名空間p簡化bean的配置
本文地址:http://mengdiqiu.com.cn/a1/Java/8741.html
您可能感興趣的文章
- 01-10Springboot中@Value的使用詳解
- 01-10如何解決線程太多導(dǎo)致java socket連接池出現(xiàn)的問題
- 01-10使用Swing繪制動態(tài)時鐘
- 01-10springboot實(shí)現(xiàn)文件上傳步驟解析
- 01-10springboot jta atomikos實(shí)現(xiàn)分布式事物管理
- 01-10如何解決java壓縮文件亂碼問題
- 01-10JAVA8獨(dú)有的map遍歷方式(非常好用)
- 01-10SpringBoot使用RabbitMQ延時隊(duì)列(小白必備)
- 01-10如何基于SpringBoot部署外部Tomcat過程解析
- 01-10SPRING BOOT啟動命令參數(shù)及源碼詳析


閱讀排行
本欄相關(guān)
- 01-10Java實(shí)現(xiàn)動態(tài)模擬時鐘
- 01-10Springboot中@Value的使用詳解
- 01-10JavaWeb實(shí)現(xiàn)郵件發(fā)送功能
- 01-10利用Java實(shí)現(xiàn)復(fù)制Excel工作表功能
- 01-10Java實(shí)現(xiàn)動態(tài)數(shù)字時鐘
- 01-10java基于poi導(dǎo)出excel透視表代碼實(shí)例
- 01-10java實(shí)現(xiàn)液晶數(shù)字字體顯示當(dāng)前時間
- 01-10基于Java驗(yàn)證jwt token代碼實(shí)例
- 01-10Java動態(tài)顯示當(dāng)前日期和時間
- 01-10淺談Java中真的只有值傳遞么
隨機(jī)閱讀
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 01-10delphi制作wav文件的方法
- 04-02jquery與jsp,用jquery
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文