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í)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Aop之AspectJ注解配置實(shí)現(xiàn)日志管理的方法
下面小編就為大家分享一篇Spring Aop之AspectJ注解配置實(shí)現(xiàn)日志管理的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01
MapStruct處理Java中實(shí)體與模型間不匹配屬性轉(zhuǎn)換的方法
今天小編就為大家分享一篇關(guān)于MapStruct處理Java中實(shí)體與模型間不匹配屬性轉(zhuǎn)換的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03
我用java實(shí)現(xiàn)了王者榮耀的皮膚和英雄技能
上篇文章主要實(shí)現(xiàn)了創(chuàng)建英雄,創(chuàng)建野怪,創(chuàng)建裝備.并且實(shí)現(xiàn)了簡單的刷怪,購買裝備等.本篇文章我優(yōu)化了我的操作界面,并且實(shí)現(xiàn)了英雄技能,英雄皮膚等,需要的朋友可以參考下2021-05-05
一文讀懂a(chǎn)va中的Volatile關(guān)鍵字使用
volatile關(guān)鍵字的作用保證了變量的可見性(visibility)。被volatile關(guān)鍵字修飾的變量,如果值發(fā)生了變更,其他線程立馬可見,避免出現(xiàn)臟讀的現(xiàn)象。這篇文章主要介紹了ava中的Volatile關(guān)鍵字使用,需要的朋友可以參考下2020-03-03
Spring Boot Admin(監(jiān)控工具)的使用
今天我們將會講解一個優(yōu)秀的監(jiān)控工具Spring Boot Admin。 它采用圖形化的界面,讓我們的Spring Boot管理更加簡單,需要的朋友可以參考下2020-02-02
SpringBoot框架實(shí)現(xiàn)切換啟動開發(fā)環(huán)境和測試環(huán)境
這篇文章主要介紹了SpringBoot框架實(shí)現(xiàn)切換啟動開發(fā)環(huán)境和測試環(huán)境,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-12-12
Shiro中session超時頁面跳轉(zhuǎn)的處理方式
這篇文章主要介紹了Shiro中session超時頁面跳轉(zhuǎn)的處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06
springboot集成mybatisplus實(shí)例詳解
這篇文章主要介紹了springboot集成mybatisplus實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-09-09

