速度模板格式

Eko*_*edy 1 java velocity template-engine

我有这样的速度模板:

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| $totalPel  Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
Run Code Online (Sandbox Code Playgroud)

当我输入 $totalPel -> 100 时,结果是:

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100  Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
Run Code Online (Sandbox Code Playgroud)

其实我想得到这样的结果:

+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| 100        Pelanggan                                      |    $totalBk |   $totalAdm |   $totalTag | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我如何制作它?

我使用这个java代码:

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());
Run Code Online (Sandbox Code Playgroud)

mcf*_*gan 5

在将它们添加到模板之前填充您的字符串。请参阅如何在 Java 中填充字符串?有关如何执行此操作的建议。