也許你需要實現自己的迭代器 - 它只是存儲BigDecimals的列表的開始和結束,並返回當前之一。通過這種方式,你可以有一個數字無限大小的列表(我認爲是你想要的,因爲你正在使用BigDecimals的。否則,只使用int或長):
#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();}
}
是否將'qty'改爲int,在bean中有效? – 2009-10-20 04:59:54