主頁(yè) > 知識(shí)庫(kù) > JSP Spring配置文件中傳值的實(shí)例詳解

JSP Spring配置文件中傳值的實(shí)例詳解

熱門標(biāo)簽:阿里云 Mysql連接數(shù)設(shè)置 服務(wù)器配置 銀行業(yè)務(wù) Linux服務(wù)器 團(tuán)購(gòu)網(wǎng)站 電子圍欄 科大訊飛語(yǔ)音識(shí)別系統(tǒng)

JSP Spring配置文件中傳值的實(shí)例詳解

通過(guò)spring提供方法,在配置文件中取傳值 

調(diào)用get方法 

      targetObject :指定調(diào)用的對(duì)象
      propertyPath:指定調(diào)用那個(gè)getter方法

    例1:

public class Test1 { 
 
  private String name = "nihao"; 
 
  public String getName() { 
    return name; 
  } 
 
} 

Xml代碼 

bean id="t1" class="i.test.Test1" /> 
 
!-- name = t1.getName() --> 
bean id="name" 
  class="org.springframework.beans.factory.config.PropertyPathFactoryBean" 
  p:targetObject-ref="t1" p:propertyPath="name" /> 

   例2:

Java代碼 

public class Test3 { 
 
  private Test1 t1 = new Test1(); 
  private String name; 
 
  public void setName(String name) { 
    this.name = name; 
  } 
 
  public Test1 getT1() { 
    return t1; 
  } 
 
} 
 

Xml代碼 

!-- 將t1的name屬性值賦給t3的name --> 
bean id="t3" class="i.test.Test3"> 
  property name="name"> 
    !-- 執(zhí)行t3.getT1().getName() --> 
    bean id="t3.t1.name" 
      class="org.springframework.beans.factory.config.PropertyPathFactoryBean" /> 
 
  /property> 
/bean> 
 

 訪問(wèn)類的Filed屬性

Java代碼 

public class Test3 { 
  public String name = "nihao"; 
  public static final int MAX_LENGTH = 10; 
} 
 

Xml代碼 

bean id="t3" class="i.test.Test3" /> 
 
!-- 訪問(wèn)成員Field 需要實(shí)例 --> 
bean id="name" 
  class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" 
  p:targetObject-ref="t3" p:targetField="name" /> 

  Xml代碼 

!-- 訪問(wèn)靜態(tài)field只需要類路徑 --> 
bean id="length" 
  class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" 
  p:targetClass="i.test.Test3" p:targetField="MAX_LENGTH" /> 
 
!-- 或者 --> 
bean id="length" 
  class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" 
  p:staticField="i.test.Test3.MAX_LENGTH" /> 
 

  調(diào)用類的方法

Java代碼 

public class Test3 { 
  public void execute(String str, int i) { 
    System.err.println(str + "--" + i); 
  } 
} 

 Xml代碼 

bean id="t3" class="i.test.Test3" /> 
 
bean 
  class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" 
  p:targetObject-ref="t3" p:targetMethod="execute"> 
  property name="arguments"> 
    list> 
      value>nihao/value> 
      value>56/value> 
    /list> 
  /property> 
/bean> 

以上就是JSP Spring配置文件中傳值的實(shí)例的文章,本站還有很多關(guān)于JSP Spring開發(fā)的文章,如有疑問(wèn),可以留言,也可以到本站社區(qū)討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

您可能感興趣的文章:
  • 詳解SpringBoot集成jsp(附源碼)+遇到的坑
  • jsp頁(yè)面數(shù)據(jù)分頁(yè)模仿百度分頁(yè)效果(實(shí)例講解)
  • jsp實(shí)現(xiàn)上一頁(yè)下一頁(yè)翻頁(yè)功能(示例代碼)
  • JSP開發(fā)之Spring方法注入之替換方法實(shí)現(xiàn)
  • 運(yùn)用JSP+ajax實(shí)現(xiàn)分類查詢功能的實(shí)例代碼
  • ResourceBundle類在jsp中的國(guó)際化實(shí)現(xiàn)方法
  • springMVC如何將controller中Model數(shù)據(jù)傳遞到j(luò)sp頁(yè)面
  • JSP Spring防止用戶重復(fù)登錄的實(shí)現(xiàn)方法

標(biāo)簽:大理 廣元 衡水 衢州 棗莊 萍鄉(xiāng) 蚌埠 江蘇

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《JSP Spring配置文件中傳值的實(shí)例詳解》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266