是否有办法执行Config.groovy
文件的操作,但在代码执行期间... ...
类似的东西:
class AController{ def method(){ withEnvironments{ development{ println 'This is execute just on development' } production { log.debug 'This is execute just on production' } } } }
我知道我可以使用if (Environment.current == 'development')
达到同样的效果,但是有什么东西与sintax ???
答案 0 :(得分:16)
找到this blog post,其中使用Environment.executeForCurrentEnvironment
显示了一种可能的解决方案:
import grails.util.Environment
class AController {
def method() {
Environment.executeForCurrentEnvironment {
development {
println 'This is execute just on development'
}
production {
log.debug 'This is execute just on production'
}
}
}
}