[英]How to store constant string in separate file in groovy script
我需要將一些常量字符串放在單獨的文件中
字符串 MYTABLE="客戶" 字符串字段="價格" 字符串......
那么如何在文件中聲明這些常量字符串以便在主文件中使用它們呢?
例如:導入 Helper.MyString
並將它們用作 MyString.MYTABLE
感謝您的幫助問候
嘗試以下
一個目錄包含兩個文件:
* ConstantStrings.groovy
* YourScript.groovy
ConstantStrings.groovy 內部
class ConstantStrings{
static String MY_STRING = "some value"
}
YourScript.groovy 內部
import ConstantStrings
log.warn("MY_STRING: ${ConstantStrings.MY_STRING}")
//should log the following: MY_STRING: some value
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.