YML配置在Grails中总是很简单

时间:2017-06-26 16:49:19

标签: grails

我想获得一些YML配置值,我可以确认我得到了正确的值。问题是,当我尝试执行某些if statement时,看起来值always true即使它是suppose to be false。我的配置如下所示:

locale
  useLangSubDir: false

代码是:

def language = ""
def useLangSubDir = grailsApplication.config.getProperty("ciab.locale.useLangSubDir")

if (useLangSubDir) { // always true
  language = "/" + WebUtils.retrieveGrailsWebRequest().getCurrentRequest().activeLocale
}

1 个答案:

答案 0 :(得分:3)

default config属性类型(来自getProperty是String)

所以你得到的字符串"false"在Groovy中是真的true,因为它不是空的,或者是空的。

你需要这样做:

def useLangSubDir = grailsApplication.config.getProperty("ciab.locale.useLangSubDir", Boolean, false)

将其设为Boolean(默认值为false

相关问题