BigDecimal 在 Velocity、Struts2 中计算为字符串
我将 struts2 与 Velocity 1.5 和 Velocity Tools 1.3 一起使用。在我的模板中,我想做一个像这样的循环:
#set ($count = ${item.qty})
#foreach($i in [1..$count])
${item.price}
...........
#end
${item.qty} 是一个 BigDecimal,但它似乎可能作为字符串传递给 Velocity。因为这个循环不起作用。替换为 $count = 5 效果很好,打印 ${item.qty} 给出的结果是 5。Velocity 1.5 和 Tools 1.3 是 Struts2 支持的最高版本。有想法吗?解决方法?谢谢
I am using struts2 with Velocity 1.5 and Velocity Tools 1.3. In my template I want to do a loop like:
#set ($count = ${item.qty})
#foreach($i in [1..$count])
${item.price}
...........
#end
${item.qty} is a BigDecimal but it seems like its passed to Velocity as a String maybe. Since this loop does not work. Replacing to $count = 5 works fine, and printing ${item.qty} gives me a result of 5. Velocity 1.5 and Tools 1.3 is the highest version Struts2 will support. Ideas? Workarounds? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要将其转换/转换为整数才能使循环正常工作。
I think you need to cast/convert it to an integer for your loop to work.
也许您需要实现自己的迭代器 - 它只会存储 bigDecimals 列表的开头和结尾,并返回当前的迭代器。这样,您就可以拥有无限大小的数字列表(我假设这就是您想要的,因为您正在使用 BigDecimals。否则,只需使用 int 或 long)
:
perhaps you need to implement your own iterator - it will just store the start and end of the list of bigDecimals, and return the current one. This way, you can have an unlimited sized list of numbers (i assume that is what you wanted because you are using BigDecimals. Otherwise, just use an int or a long):
and