Spring EL bean參考示例

2021-10-06 19:55:13 字數 1703 閱讀 5864

在spring el中,您可以使用'點(。)'符號引用bean和巢狀屬性。 例如,「bean.property_name」。

public class customer ")

private string country;

在上面的**片段中,它將「addressbean」 bean中「country」屬性的值注入到當前的「customer」類中的「country」屬性中。

請參見下面的示例,向您展示如何使用spel引用bean,bean屬性以及它的方法。

package com.mkyong.core;

import org.springframework.beans.factory.annotation.value;

import org.springframework.stereotype.component;

@component("customerbean")

public class customer ")

private address address;

@value("#")

private string country;

@value("#")

private string fulladdress;

//getter and setter methods

@override

public string tostring()

}

package com.mkyong.core;

import org.springframework.beans.factory.annotation.value;

import org.springframework.stereotype.component;

@component("addressbean")

public class address

//getter and setter methods

public void setcountry(string country)

@override

public string tostring()

}

執行

customer obj = (customer) context.getbean("customerbean");

system.out.println(obj);

輸出量

customer [address=address [street=block abc, lakeview, postcode=98700, country=us]

, country=us

, fulladdress=mkyong : block abc, lakeview 98700 us]

請參見bean定義xml檔案中的等效版本。

標籤: 春天el

spring3

翻譯自:

Spring EL bean引用例項

在spring el,可以使用點 符號巢狀屬性參考乙個bean。例如,bean.property name public class customer private string country 在上面的 片段,它從 addressbean bean注入了 country 屬性到現在的 custo...

NSDictionary plist簡單示例

在iphone ipad工程裡面,新增 file other property list,例如 test.plist,然後在其中新增3個專案 key name,date,dept,並填充value值。以下為對此test.plist檔案的一系列常用操作 myname,mydate,mydept為定義的...

NSDictionary plist簡單示例

在iphone ipad工程裡面,新增 file other property list,例如 test.plist,然後在其中新增3個專案 key name,date,dept,並填充value值。以下為對此test.plist檔案的一系列常用操作 myname,mydate,mydept為定義的...