让我在application.properties中具有以下属性
url.2019=http://example.com/2019
url.2020=http://example.com/2020
而且我有此方法,
public String getUrl(String year) {
String url;
// here I want to read the property value based on the value of year
// if year is "2019", I want to get the value of ${url.2019}
// if year is "2020", I want to get the value of ${url.2020}
// something like #{url.#{year}} ??
return url;
}
实现此目标的最佳方法是什么?
谢谢。
我认为一个选项可能正在使用.yml
文件
url:
2019: url1.com
2010: url2.com
2021: url3.com
然后,您可以轻松读取诸如:]的属性>
String year = // get year dynamically from somewhere
@Value("#{'url' + year}")
private String urlOfYear;
application.properties:
可能有多种方法可以实现这一目标