springspring-mvcproperty-placeholderapplication.properties

How to select several properties for specific name


I am working on a web project using Spring and Spring MVC.

I have a feature that is the same for 3 different elements (which are available in dropdown in view). Only two parameters change for each item. I decided to put these elements and parameters in a .properties file to permit the user change them. So for example in my .properties I have the following:

FC
fcUuid=11111111111111111
fcTag=tag1

AC
itUuid=22222222222222222
itTag=tag2

IT
acUuid=333333333333333333
acTag=tag3

For the moment I am able to retrieve each element separately.

For example:

 String communityUuid = SpringPropertiesUtil.getProperty("fcUuid");

(SpringPropertiesUtil extends PropertyPlaceholderConfigurer)

But my question is: how can I retrieve all the parameters relative to one element?

For example the user selects "FC", how in my service layer can I retrieve both fcUuid and fcTag parameters?

Of course I can do something like:

 if(param="FC"){
     String communityUuid = SpringPropertiesUtil.getProperty("fcUuid");
     String communityTag = SpringPropertiesUtil.getProperty("fcTag");
 } else if (param="AC"){...}

But I don't want to do that because the user can add elements so I would have to modify the code each time.

I would like something like:

String communityUuid = SpringPropertiesUtil.getProperties(param[0]);
String tagUuid = SpringPropertiesUtil.getProperties(param[1]);

Or even better:

String communityUuid = SpringPropertiesUtil.getProperties(param[uuid]);
String tagUuid = SpringPropertiesUtil.getProperties(param[tag]);

Solution

  • With the help of one of my colleagues I managed to realize that. This is how I proceeded: