我有通過地圖迭代,並顯示該信息爲這樣的模板:爲什麼模板不能提供正確的值?
#{list items:report.getCategoryMap()?.keySet(), as:'cat'}
%{models.reporting.TransactionReportItem item = report.getCategoryMap()?.get(cat);}%
${cat}
${item?.nbCredit}
${item?.getCreditPerc(report.nbCredit)}
${item?.nbDebit}
${item?.getDebitPerc(report.nbDebit)}
${item?.getTotalTransactions()}
#{/list}
出於某種原因,模板總是呈現getCreditPerc和getDebitPerc的結果爲0.0
public Double getCreditPerc(long totalCredit){
double perc = (double) (nbCredit/totalCredit);
Logger.info("nbCredit: %s, total cr: %s", nbCredit, totalCredit);
return new Double(perc);
}
當調用模板我可以看到日誌中的輸出:
2011-11-21 13:54:22 INFO〜[TransactionReportItem:85] getDebitPerc() - nbDebit:39,total cr:4984
我嘗試使用原始類型而不是雙重對象沒有成功。 當調試代碼時,我可以看到所有的值都被正確設置。
難道這與groovy模板渲染有關嗎?
沒錯剛剛意識到。 TX。 – emt14
沒有看到您的帖子,我張貼相同;) – mandubian