对messages.properties的参数问题,除零之外的所有数字都正常工作

cbl*_*to7 0 grails groovy gsp

在我的Grails 2.4.4应用程序中,我使用messages.properties进行国际化,具有以下值:

my.app.thing.allowance(s)={0} Allowance(s)
Run Code Online (Sandbox Code Playgroud)

它正在使用像这样的gsp:

<g:message code="my.app.thing.allowance(s)" args="${item.allowances.size()}"/>
Run Code Online (Sandbox Code Playgroud)

对于任何大于0的值,都会正确显示该消息,例如,如果item.allowances.size() == 4显示的消息是,则显示消息4 Allowances(s)

问题是,如果item.allowances.size() == 0那时显示的消息是{0} Allowance(s)

我试图用几种不同的方式编写args,例如:

<g:message code="my.app.thing.allowance(s)" args="${item.allowances.isEmpty() ? 0.intValue() : item.allowances.size()}"/>
Run Code Online (Sandbox Code Playgroud)

我调试过的东西,我确信item.allowances.size() == 0但由于某种原因,它无法正确处理值0.将一个int值为0的参数传递给messages.properties的正确方法是什么?

Bha*_*ija 6

g.message参数中总是作为一个传递List.

来自:http://docs.grails.org/3.0.17/ref/Tags/message.html

args(可选) - 使用代码时应用于消息的参数值列表.

请尝试使用此代码:

<g:message code="my.app.thing.allowance(s)" args="[item.allowances.size()]"/>
Run Code Online (Sandbox Code Playgroud)