这是我的班级,我正在阅读一个属性文件,有两个文件Config.groovy,我有方法,Call.groovy,我从config调用方法,期待返回。
Config.groovy中
class Config
{
public methodParse {
Properties properties = new Properties()
File propertiesFile = new File('src/main/resources/application.properties')
propertiesFile.withInputStream
{
properties.load(it)
}
String value = properties."$name"
return value
}
}
load.groovy
def config = new Config ()
config.methodParse "environments.local.logfile"
println (config.methodParse());
如何让load.groovy传递一个参数,然后打印收到的内容?
答案 0 :(得分:0)
如果我理解正确怎么办。
class Config {
public methodParse(String name) {
Properties properties = new Properties()
File propertiesFile = new File('src/main/resources/application.properties')
propertiesFile.withInputStream {
properties.load(it)
}
properties."$name"
}
}
用法:
def config = new Config ()
config.methodParse "environments.local.logfile"
答案 1 :(得分:0)
忽略语法错误 你可以试试像
这样的东西 class Config
{
public String methodParse (String name)
{
Properties properties = new Properties()
File propertiesFile = new File('src/main/resources/application.properties')
propertiesFile.withInputStream
{
properties.load(it)
}
String value = properties."$name"
return value
}
}
def config = new Config ()
the_value =config.methodParse("environments.local.logfile")
println (conf_value);
答案 2 :(得分:0)
我能够解决这个问题,这就是我做的事情
def config = new Config() String conf_value = config.methodParse(" environments.local.logfile") println conf_value