简体   繁体   English

如何在Grails中的gsp上根据环境在Config.groovy中设置值并获得相同参数的不同值?

[英]how to set value in Config.groovy and get different value for same parameter according to environment on gsp in Grails?

I have a situation. 我有情况 I want to set one value to some parameter in Config.groovy in my Grails project. 我想在Grails项目的Config.groovy中为某个参数设置一个值。 This parameter should have different value for each environment, ie for dev environment it is like abc = "devValue", for test environment like abc="testValue" and for production environment like abc="prodValue". 对于每个环境,此参数应具有不同的值,即对于开发环境,它类似于abc =“ devValue”,对于测试环境,例如abc =“ testValue”,对于生产环境,例如abc =“ prodValue”。 and then I want to set that value as a hidden field value on gsp page according to running environment. 然后我想根据运行环境将该值设置为gsp页面上的隐藏字段值。

There's already an example of this in the Config.groovy that's generated for you: 为您生成的Config.groovy中已经有一个示例:

environments {
   development {
      grails.logging.jul.usebridge = true
   }
   production {
      grails.logging.jul.usebridge = false
   }
}

so you can just add your setting there: 因此您只需在此处添加设置即可:

environments {
   development {
      grails.logging.jul.usebridge = true
      abc = "devValue"
   }
   test {
      abc = "testValue"
   }
   production {
      grails.logging.jul.usebridge = false
      abc = "prodValue"
   }
}

Thanks Igor Artamonov, 感谢Igor Artamonov,

I found the solution below. 我在下面找到了解决方案。

I added code below in Config.groovy 我在Config.groovy中添加了以下代码

environments {
development {
          abc="devValue"
}

test {
          abc="testValue"
}

production {
          abc="prodValue"
 }
}

And then in gsp i set the hidden field as below. 然后在gsp中,我将隐藏字段设置如下。

<input id="oid" type="hidden" name="oid" value="${grailsApplication.config.abc}">

Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM