格式化值在作为参数传递给spring消息标记时会丢失其格式

时间:2014-05-10 12:40:50

标签: java spring-mvc localization jstl

给定一个带键的属性文件

property.code=Text goes here {0}

并且

discountPercentage = 5.0

当我这样做时

<fmt:formatNumber value="${discountPercentage / 100}" var="discount"
      type="PERCENT" minFractionDigits="1" maxFractionDigits="1" />             
<spring:message code="property.code" arguments="${discount}"  />

然后弹簧消息标签剥离小数位和%符号,只显示5而不是5.0%

无法弄清楚这里发生了什么......我认为它会起作用。

1 个答案:

答案 0 :(得分:2)

我的猜测是,您的本地制作的格式为5,0%,而不是5.0%。 Spring消息标记的arguments属性需要以逗号分隔的参数列表。

尝试根本不传递分隔符或伪分隔符:

<spring:message code="property.code" arguments="${discount}" argumentSeparator="${null}" />

<spring:message code="property.code" arguments="${discount}" argumentSeparator="" />

<spring:message code="property.code" arguments="${discount}" argumentSeparator="fake" />