[英]How to store constant string in separate file in groovy script
I need to place some constant string in separate file as我需要将一些常量字符串放在单独的文件中
String MYTABLE="Customer" String FIELD="Price" String......字符串 MYTABLE="客户" 字符串字段="价格" 字符串......
Then how can declare those constant string in the file in order o use them in the main file?那么如何在文件中声明这些常量字符串以便在主文件中使用它们呢?
Ex: import Helper.MyString例如:导入 Helper.MyString
and use them as MyString.MYTABLE并将它们用作 MyString.MYTABLE
Thanks for help regards感谢您的帮助问候
Try the following尝试以下
one directory contains two files:一个目录包含两个文件:
* ConstantStrings.groovy
* YourScript.groovy
Inside ConstantStrings.groovy ConstantStrings.groovy 内部
class ConstantStrings{
static String MY_STRING = "some value"
}
Inside YourScript.groovy YourScript.groovy 内部
import ConstantStrings
log.warn("MY_STRING: ${ConstantStrings.MY_STRING}")
//should log the following: MY_STRING: some value
Hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.