开发者

velocity template format

I Have velocity template like this one :

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| $totalPel  Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+

When i put $totalPel -> 100, the result is :

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100  Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $to开发者_如何转开发talTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+

Actually I want to get the result like this :

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100        Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+

Anyone can show me how to make it?

I use this java code :

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());


Pad your strings before adding them to your template. See How can I pad a String in Java? for advice on how to do this.


You can either transform the value into a String and pad it, or you can simply add more space in your template, I believe velocity maintains whitespace that you define.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜