- 方案1 -爪哇 - 從物業獲取值文件
這是我的屬性文件:
template.lo=rule A | template B
template.lo=rule B | template X
template.lo=rule C | template M
template.lo=rule D | template G
我不認爲上面的設計是允許因爲有重複鍵
- - 方案2 -
template.lo1=rule A | template B
template.lo2=rule B | template X
template.lo3=rule C | template M
template.lo4=rule D | template G
上述設計是絕對允許的。
我想從Java中檢索值,所以我會通過密鑰來獲取值。通常情況下,我會用這樣的方式:
PropertyManager.getValue("template.lo1",null);
問題的關鍵是將繼續增加,在上面的例子中有4 ...在未來有可能是5或10
所以,我的問題是,我將如何檢索所有值?
如果我知道總共有10項,我可以用這樣的方式:
List <String> valueList = new ArrayList<String>();
for(int i = 1; i<totalNumberOfKeys+1; i++{
String value = (String) PropertyManager.getValue("template.lo"+i,null)
valueList.add(value);
}
,但問題是我沒有上的按鍵數量的任何想法。我不能拉所有的價值,因爲會有其他我不想要的鑰匙。
對此有何想法?
你可以使用一個單一的屬性值和使用分隔符來分割。像「template.lo =規則A |模板B,規則B |模板X,規則C |模板M」 – Todoy