2011-10-05 117 views
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()); 
+0

我真的不明白你想在這裏...有什麼區別?只是更多的空間?這通常在模板中進行控制。 – pcalcao

+0

是的,我只是想爲結果自動添加空間。當我輸入很多參數時,這很有用:D –

回答

2

您可以將值轉換爲字符串並填充它,或者您可以簡單地在模板中添加更多空間,我相信速度會保留您定義的空白。