春ブーツのプロパティファイルを反復処理をロードしてする方法

サム:

私はきたproperties値がカンマ区切りされたファイルを。私はと値を取得することができるよObject下記のように。誰がどのような値を分離し、文字列でそれを得るために私に教えてもらえます。

。プロパティ

key-1 = value1,value11
key-2 = value2,value22
key-3 = value3,value33
key-4 = value4,value44

コード

@PropertySource( value = "classpath:test1.properties", name = "test1" )

AbstractEnvironment ae = (AbstractEnvironment)env;
org.springframework.core.env.PropertySource test1Source = 
ae.getPropertySources().get("test1");
Properties propsTest1 = (Properties)test1Source.getSource();

   for(Object key : propsTest1.keySet()){
   System.out.println("Properties file======>   propsTest1.get(key));
  }
ビナイAvasthi:

あなたは、以下のような何かを試すことができます。

Properties propsTest1 = (Properties)test1Source.getSource();

for(Map.Entry<Object, Object> e : propsTest1.entrySet()){

   String value = (String)e.getValue();
   String[] values = value.split(",");
   // If you have spaces as between values, you have to take care of it.
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=224756&siteId=1