velocity - 如何在 Velocity 中使用文本文件
问题描述
我有一个名为 data.txt 的文本文件,其中包含客户的详细信息。我需要使用 apache velocity 向每个客户发送一条消息。我的文件看起来像这样
enter code here
First_Name, City, ...
Rakesh, Hyderabad,...
Jack, berlin,...
...., ...., ...
像这 10000 条记录是他们的.. 我不太了解 apache 速度.. 我无法以速度加载我的文件。我的java文件
public static void main(String[] args) throws Exception {
Velocity.init();
Template t = Velocity.getTemplate("./src/VMDemo.vm");
VelocityContext ctx = new VelocityContext();
Writer writer = new StringWriter();
t.merge(ctx, writer);
System.out.println(writer);
虚拟机文件
#if ($City == "Hyderabad")
Hi $first_Name welcome to Hyderabad.
#elseif ($City == "Berling")
Hi $First_Name welcome to Berlin
#elseif ($City == "Mumbai")
Hi $First_Name welcome to Mumbai
#else
Please contact Us
#end
enter code here
the output should be like this..
Hi Rakesh welcome to Hyderabad.
有人请建议我如何加载数据并以速度使用。如果 Person 属于某个城市,则应从文件中动态获取名称。请有人帮我解决这个问题..帮我把我的文件包括在速度中。
解决方案
推荐阅读
- c++ - Visual Studio cmake远程linux开发mysql中的分段错误
- java - Android:如何在 Question1 类中使用方法 emitBubbles()
- python - 我使用 Pandas 掩码通过使用输入日期从数据框中获取数据,但开始日期的日期没有出现
- react-native - HeaderButtons.js 有什么问题?
- c# - 如何声明一个空的 ClientContext
- xml - Spring 4 控制器字符串到 XML 响应
- kotlin - 如何使用 TestPropertyProvider 并使用 Kotlin 向 Micronaut 注入 RxHttpClient
- c# - 如何从 WPF 中的项目容器中获取项目?
- diff - 如何在 sphinx 的重组文本中突出显示差异输出文本?
- javascript - 使用 appendChild 时 justify 属性无效