我在grails项目上工作
def result = "customer"
//(this value is according to returned method parameter,
//it may be customer, company,... & so on)
def messages = "${message(code: 'default.result.${result}', default:'${result}')}"
我需要在上面提到的消息代码中发送一个变量
问题:此代码显示为
default.result.${result}
message.properties中没有代码引用这些代码
there is default.result.customer ....$ so on
问题:如何在消息代码中发送变量?
答案 0 :(得分:2)
尝试省略双引号(GString),它应该如下所示:
def xxx = "bar"
def m = message(code: "foo.${xxx}", args: ['hello world'])
以下消息代码中的结果
foo.bar
答案 1 :(得分:2)
尝试:
def messages = message(code: 'default.result.' + result, default: result)
如果您想传入一些值,例如一个字符串,您可以像这样定义您的消息:
default.result.success = Action {0} was successfull.
并解决您的代码:
def m = message(code: 'default.result.' + result, args: ['delete User'])