开发者

velocity template format

开发者 https://www.devze.com 2023-04-11 03:57 出处:网络
I Have velocity template like this one : +-----------------------------------------------------------+-------------+-------------+-------------+-------------+

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

精彩评论

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