速度模板格式
我有这样的速度模板:
+-----------------------------------------------------------+-------------+-------------+-------------+-------------+
| $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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在将字符串添加到模板之前先填充它们。请参阅如何在 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.
您可以将值转换为字符串并填充它,或者您可以简单地在模板中添加更多空间,我相信速度会保留您定义的空白。
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.