例子描述:
我们在日常工作中,经常会遇到字典关联的场景,比如:
张三,19,1
李四,19,2
王五,19,3
将后面的数字关联成职业
张三,19,司机
李四,19,厨师
王五,19,警察
这是一个简单的场景,往往在实际当中,后面需要关联的内容是一个字典表。下面请看例子
代码片段:
创建字典
读取配置文件方法
/* 获取配置文件套路1 */
def getConfig(path: String): scala.collection.Map[String, String] = {
val prop = new Properties()
val inputStream = this.getClass.getResourceAsStream(path)
try {
prop.load(inputStream)
prop
} finally inputStream.close()
}
字典使用方法
val data_location = ConfigUtils.getConfig("/label/BusinessLocation.properties")
data_location.getOrElse("USR_NBR", "")
${line((data_location.getOrElse("USR_NBR", "").toInt))}