【发布时间】:2011-11-21 10:59:02
【问题描述】:
我有一个模板,它遍历地图并显示信息:
#{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 模板渲染有关?
【问题讨论】:
标签: java groovy playframework template-engine