0
我有Velocity模板像這樣的:Velocity模板格式
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| $totalPel Pelanggan | $totalBk | $totalAdm | $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
當我把$ totalPel - > 100,結果是:
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100 Pelanggan | $totalBk | $totalAdm | $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
其實我想要得到這樣的結果:
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100 Pelanggan | $totalBk | $totalAdm | $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
任何人都可以告訴我如何做到這一點?將它們添加到您的模板之前
Velocity.init();
VelocityContext context = new VelocityContext();
context.put("totalPel", 100);
Template template = Velocity.getTemplate("LaporanTagihan.txt");
StringWriter writer = new StringWriter();
template.merge(context, writer);
System.out.println(writer.toString());
我真的不明白你想在這裏...有什麼區別?只是更多的空間?這通常在模板中進行控制。 – pcalcao
是的,我只是想爲結果自動添加空間。當我輸入很多參數時,這很有用:D –