我想根据提供的fileType和companyName
获取电子邮件ID列表def getEmailAddresses(fileType: String, companyName: String): List[String] = {
val xz = Play.application.configuration.getConfigList("email_list")
println(xz)
}
我的上面的函数给了我一些复杂的配置列表,它不容易遍历。
我基本上想要List[String]
,这只是电子邮件ID列表。
例如,给定参数:
我想获得字符串"user1@gmail.com, user2@gmail.com"
可以通过List[String]
.split(",").toList
这可以简化吗?
以下是我在scala play应用程序中的application.conf文件
email_list = [
{
file0 : "user1@gmail.com,user2@gmail.com"
},
{
file1 : [
{"company1" : "user1@gmail.com"},
{"company2" : "user1@gmail.com"},
{"company3" : "user1@gmail.com"}
]
},
{
top2 = [
{"company1": "user1@gmail.com,user2@gmail.com"},
{"company2": "user1@gmail.com,user2@gmail.com"},
{"company3": "user1@gmail.com,user2@gmail.com"}
]
},
{
test_2 = [
{"company1": "user1@gmail.com,user2@gmail.com"},
{"company2": "user1@gmail.com,user2@gmail.com"},
{"company3": "user1@gmail.com,user2@gmail.com"}
]
},
{
xyz_7 = [
{"company1": "user1@gmail.com,user2@gmail.com"},
{"company2": "user1@gmail.com,user2@gmail.com"},
{"company3": "user1@gmail.com,user2@gmail.com"}
]
},
{
abc_def = [
{"company1": "user1@gmail.com,user2@gmail.com"},
{"company2": "user1@gmail.com,user2@gmail.com"},
{"company3": "user1@gmail.com,user2@gmail.com"}
]
}
]
答案 0 :(得分:0)
我已经对HOCON语法进行了一些试验,发现以下代码+配置正常工作
码
def getEmailAddresses(fileType: String, companyName: String): List[String] = {
// fileType = "file1"
// companyName = "company1"
val file0 = Play.application.configuration.getString("email_list.file0")
println(file0)
val file1_company1 = Play.application.configuration.getString(s"email_list.${fileType}.${companyName}")
println(file1_company1)
}
application conf
email_list {
file0 = "user1@gmail.com,user2@gmail.com"
file1 {
company1 = "user1@gmail.com"
company2 = "user1@gmail.com"
company3 = "user1@gmail.com"
}
top2 {
company1 = "user1@gmail.com,user2@gmail.com"
company2 = "user1@gmail.com,user2@gmail.com"
company3 = "user1@gmail.com,user2@gmail.com"
}
test_2 {
company1 = "user1@gmail.com,user2@gmail.com"
company2 = "user1@gmail.com,user2@gmail.com"
company3 = "user1@gmail.com,user2@gmail.com"
}
xyz_7 {
company1 = "user1@gmail.com,user2@gmail.com"
company2 = "user1@gmail.com,user2@gmail.com"
company3 = "user1@gmail.com,user2@gmail.com"
}
abc_def {
company1 = "user1@gmail.com,user2@gmail.com"
company2 = "user1@gmail.com,user2@gmail.com"
company3 = "user1@gmail.com,user2@gmail.com"
}
}