Spring 給bean配置list列表引數
阿新 • • 發佈:2019-01-08
public class OmsSetting extends AppSetting { ... public static class CompanyBean implements Serializable{ private static final long serialVersionUID = -7908969848589945536L; private String companyName; //公司名 public String getCompanyName() { return companyName; } public void setCompanyName(String companyName) { this.companyName = companyName; } public String getLogoPath() { return logoPath; } public void setLogoPath(String logoPath) { this.logoPath = logoPath; } public String getSealPath() { return sealPath; } public void setSealPath(String sealPath) { this.sealPath = sealPath; } private String logoPath; //公司Logo路徑 private String sealPath; //公章圖片路徑 } public static List<CompanyBean> companys; public static List<CompanyBean> getCompanys() { return companys; } public static void setCompanys(List<CompanyBean> companys) { OmsSetting.companys= companys; } }
OMSSetting裡面有一支屬性為list<CompanyBean>, 下面看如何為其裝配內容:
<property name="companys"> <list> <bean class="com.freestyle.oms.OmsSetting.CompanyBean"> <property name="companyName"> <value>東莞市AA科技有限公司</value> </property> <property name="logoPath"> <value>media/image/company/logo_1.png</value> </property> <property name="sealPath"> <value>media/image/company/gz_1.png</value> </property> </bean> <bean class="com.freestyle.oms.OmsSetting.CompanyBean"> <property name="companyName"> <value>東莞市BB科技有限公司</value> </property> <property name="logoPath"> <value>media/image/company/logo_2.png</value> </property> <property name="sealPath"> <value>media/image/company/gz_2.png</value> </property> </bean> </list> </property>
網上很多都是先定義bean1,bean2, 然後在list裡面ref引用, 我覺得如果這些list item沒有其他用途的話還這樣做就畫蛇添足了, 直接做在裡面即可 .