Groovy - 使用 message.properties 列出字符串

Groovy - list to String with message.properties

是否有任何 Groovy 方法可以将 List 转换为 String 并用消息属性替换值?

<g:message code="label.promotion.create.short.${command.daysList.join(",")}"/>

来自 list 的输出数据,而我想要 code 需要从 message.properties 中获取,作为逗号分隔

显然我可以通过迭代列表来做到这一点,就像这样

<g:each in="${command.daysList}" var="day" status="count">
    <g:message code="label.promotion.create.short.${day}"/>
    <g:if test="${count+1 < command.daysList.size()}">, </g:if>
</g:each>

没有捷径可走。您可以在您的视图中使用它:

command.dayList.collect{ message(code: "label...${it}") }.join(", ")