Thymeleaf#numbers.formatInteger奇怪的行为

时间:2015-03-13 11:26:01

标签: java spring-mvc thymeleaf

我正在使用spring mvc和thymeleaf作为模板引擎为web应用程序开发用户故事。

我的控制器将包含名为quantite的BigDecimal字段的对象传递给我的视图。即使它是BigDecimal,我也需要将它渲染为Integer,因为它永远不会有一个小数组件,所以我的目标是将BigDecimal像50.00渲染到50 我在视图中渲染它Thymeleaf使用以下语法。

<span th:text="${#numbers.formatInteger(placAction.quantite,2,'POINT')}"></span> 

这意味着我想将数字格式化为整数以显示最少两位数,并将该点用作千位分隔符。

下图显示了我的结果

format not applied

因此格式未正确应用。当我测试这种行为时,我注意到在表达式中添加一个litteral会激发数字的正确呈现。例如,我用这种方式更改了上一个表达式:

<span th:text="${#numbers.formatInteger(placAction.quantite,2,'POINT')} + ' (no units)'"></span>

这是一个说明渲染的图像

format correctly applied

正如您现在所看到的,格式已正确呈现。我不明白这种奇怪的行为,似乎Thymeleaf不应用#numbers.formatInteger,直到我用一个litteral求和它的结果,并且只有当litteral不是空白时(仅由空格组成)我也测试过

<span th:text="${#numbers.formatInteger(placAction.quantite,2,'POINT')} + ' '"></span>

但它没有产生预期的结果。在表达式中添加非空白文本的每个更改都会正确呈现,但后来我有一个不需要的附加文本,但是当我删除它时,渲染再次不正确。所以非常欢迎任何解决这个问题的帮助。

1 个答案:

答案 0 :(得分:2)

如果您使用的是thymeleaf 2.0版本,请尝试使用

angular.js:13236 ReferenceError: gameData is not defined
at new <anonymous> (dataService.js:18)
at Object.instantiate (angular.js:4619)
at Object.<anonymous> (angular.js:4459)
at Object.invoke (angular.js:4604)
at Object.$get (angular.js:4443)
at Object.invoke (angular.js:4604)
at angular.js:4403
at d (angular.js:4550)
at e (angular.js:4574)
at Object.invoke (angular.js:4596)
相关问题