2017-08-09 69 views
1

我也碰到過,其屬性的名稱爲後綴的整數值一些Java屬性文件來表示這樣的順序:Java屬性文件,其中屬性名後綴有整數值

ui.js.include.0 = /file1.js 
ui.js.include.1 = /file2.js 

然後一個JSP頁面將讀取這些屬性與這樣的標籤:

<c:forEach var="jsInclude" items"${ui.js.include}"> 
    // some codes to proceed the jsInclude variable 
</c:forEach> 

誰能告訴我在哪裏,這種技術從何而來?有關它的任何官方文檔?

回答

0

屬性延伸哈希表(這反過來,實現了Map),所以就像是通過與進入一個HashMap迭代。

1

此技術來源於Spring framework及其PropertyPlaceholderConfigurer

是很常見的Spring應用程序使用Properties豆。您可以從您的視圖這樣(假設你使用InternalResourceViewResolver)訪問:

<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
    <property name="locations"> 
     <list><value>classpath:config.properties</value></list> 
    </property> 
</bean> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/views/"/> 
    <property name="suffix" value=".jsp"/> 
    <property name="exposedContextBeanNames"> 
     <list><value>properties</value></list> 
    </property> 
</bean> 

然後,在你的JSP,你可以使用${properties.myProperty}${properties['my.property']}