Spring實(shí)戰(zhàn)之獲取其他Bean的屬性值操作示例-創(chuàng)新互聯(lián)

本文實(shí)例講述了Spring實(shí)戰(zhàn)之獲取其他Bean的屬性值操作。分享給大家供大家參考,具體如下:

創(chuàng)新互聯(lián)主營凱里網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都App制作,凱里h5成都微信小程序搭建,凱里網(wǎng)站營銷推廣歡迎凱里等地區(qū)企業(yè)咨詢

一 配置

<?xml version="1.0" encoding="GBK"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://www.springframework.org/schema/beans"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
   http://www.springframework.org/schema/util
   http://www.springframework.org/schema/util/spring-util-4.0.xsd">
   <!--下面配置定義一個(gè)將要被引用的目標(biāo)bean-->
   <bean id="person" class="org.crazyit.app.service.Person">
      <property name="age" value="30"/>
      <property name="son">
        <!-- 使用嵌套Bean定義setSon()方法的參數(shù)值 -->
        <bean class="org.crazyit.app.service.Son">
           <property name="age" value="11" />
        </bean>
      </property>
   </bean>
   <!-- 將指定Bean實(shí)例的getter方法返回值定義成son1 Bean -->
   <bean id="son1" class=
      "org.springframework.beans.factory.config.PropertyPathFactoryBean">
      <!-- 確定目標(biāo)Bean,指定son1 Bean來自哪個(gè)Bean的getter方法 -->
      <property name="targetBeanName" value="person"/>
      <!-- 指定son1 Bean來自目標(biāo)bean的哪個(gè)getter方法,son代表getSon() -->
      <property name="propertyPath" value="son"/>
   </bean>
   <!-- 簡化配置
   <util:property-path id="son1" path="person.son"/> -->
   <!-- 下面定義son2 Bean -->
   <bean id="son2" class="org.crazyit.app.service.Son">
      <property name="age">
        <!-- 使用嵌套Bean為調(diào)用setAge()方法指定參數(shù)值 -->
        <!-- 以下是訪問指定Bean的getter方法的簡單方式,
        person.son.age代表獲取person.getSon().getAge()-->
        <bean id="person.son.age" class=
           "org.springframework.beans.factory.config.PropertyPathFactoryBean"/>
      </property>
   </bean>
   <!-- 簡化配置
   <bean id="son2" class="org.crazyit.app.service.Son">
      <property name="age">
        <util:property-path path="person.son.age"/>
      </property>
   </bean> -->
   <!-- 將基本數(shù)據(jù)類型的屬性值定義成Bean實(shí)例 -->
   <bean id="theAge" class=
      "org.springframework.beans.factory.config.PropertyPathFactoryBean">
      <!-- 確定目標(biāo)Bean,表明theAge Bean來自哪個(gè)Bean的getter方法的返回值 -->
      <property name="targetBeanName" value="person"/>
      <!-- 使用復(fù)合屬性來指定getter方法。son.age代表getSon().getAge() -->
      <property name="propertyPath" value="son.age"/>
   </bean>
   <!-- 簡化配置
   <util:property-path id="theAge" path="person.son.age"/> -->
   <!-- 將基本數(shù)據(jù)類型的屬性值定義成Bean實(shí)例 -->
   <bean id="theAge2" class=
      "org.springframework.beans.factory.config.PropertyPathFactoryBean">
      <!-- 確定目標(biāo)Bean,表明theAge2 Bean來自哪個(gè)Bean的屬性。
        此處采用嵌套Bean定義目標(biāo)Bean -->
      <property name="targetObject">
        <!-- 目標(biāo)Bean不是容器中已經(jīng)存在的Bean, 而是如下的嵌套Bean-->
        <bean class="org.crazyit.app.service.Person">
           <property name="age" value="30"/>
        </bean>
      </property>
      <!-- 指定theAge2 Bean來自目標(biāo)bean的哪個(gè)getter方法,age代表getAge() -->
      <property name="propertyPath" value="age"/>
   </bean>
</beans>

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站bm7419.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

分享標(biāo)題:Spring實(shí)戰(zhàn)之獲取其他Bean的屬性值操作示例-創(chuàng)新互聯(lián)
鏈接分享:http://bm7419.com/article6/hdsog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷ChatGPT、App開發(fā)、小程序開發(fā)、網(wǎng)頁設(shè)計(jì)公司品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化