我正在使用Spring和Spring MVC開發Web項目。如何爲特定名稱選擇多個屬性
我有一個功能是3個不同的元素(可在下拉菜單中查看)相同。每個項目只有兩個參數會發生變化。我決定將這些元素和參數放在.properties
文件中以允許用戶更改它們。所以例如在我的.properties我有以下內容:
FC
fcUuid=11111111111111111
fcTag=tag1
AC
itUuid=22222222222222222
itTag=tag2
IT
acUuid=333333333333333333
acTag=tag3
目前,我能夠單獨檢索每個元素。
例如:
String communityUuid = SpringPropertiesUtil.getProperty("fcUuid");
(SpringPropertiesUtil
延伸PropertyPlaceholderConfigurer
)
但我的問題是:我怎麼可以檢索相對於一個元素的所有參數?
例如,用戶選擇「FC」,我的服務層如何檢索fcUuid和fcTag參數?
我當然可以這樣做:
if(param="FC"){
String communityUuid = SpringPropertiesUtil.getProperty("fcUuid");
String communityTag = SpringPropertiesUtil.getProperty("fcTag");
} else if (param="AC"){...}
但我不想這樣做,因爲用戶可以添加元素,因此我會在每次修改代碼。
我想是這樣的:
String communityUuid = SpringPropertiesUtil.getProperties(param[0]);
String tagUuid = SpringPropertiesUtil.getProperties(param[1]);
甚至更好:
String communityUuid = SpringPropertiesUtil.getProperties(param[uuid]);
String tagUuid = SpringPropertiesUtil.getProperties(param[tag]);
https://開頭計算器。com/questions/23506471/spring-access-all-environment-properties-as-a-map-or-properties-object選中此項即可獲得所有屬性 – StanislavL
實際上,我已將我的文件轉換爲我的'SpringPropertiesUtil'中的hashmap上課,這就是允許我一次獲得一個物業的原因。但是它對我的情況有何幫助? –
你可以通過所有的map鍵,並檢查一個鍵是否以所需的前綴開頭並返回 – StanislavL