也许您需要实现自己的迭代器 - 它只会存储 bigDecimals 列表的开头和结尾,并返回当前的。这样,您可以拥有无限大小的数字列表(我假设这是您想要的,因为您使用的是 BigDecimals。否则,只需使用 int 或 long):
#set ($countIterator = ${item.qtyIterator})
#foreach($i in $countIterator)
${i}
....use $i as a string...
#end
和
public class QuantityIterator implement Iterator<BigDecimal> {
QuantityIterator(BigDecimal start, BigDecimal end) { this.start = start;this.end=end;}
//..implement the iterator methods like hasNext() etc
public hasNext() {return this.current.compareTo(this.end) < 0;} //current <= end
public BigDecimal next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
this.current = this.current.add(BigDecimal.ONE);
return this.current;
}
public void remove(){throw new UnsupportedException();}
}