速度模板格式

发布于 2024-12-08 04:07:22 字数 1561 浏览 0 评论 0原文

我有这样的速度模板:

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

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

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

实际上我想得到这样的结果:

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

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

我使用这个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());

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 | $totalTotal |
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的十字路口 2024-12-15 04:07:22

在将字符串添加到模板之前先填充它们。请参阅如何在 Java 中填充字符串?获取建议关于如何做到这一点。

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.

数理化全能战士 2024-12-15 04:07:22

您可以将值转换为字符串并填充它,或者您可以简单地在模板中添加更多空间,我相信速度会保留您定义的空白。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文