首页 > 解决方案 > 如何在 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 属于某个城市,则应从文件中动态获取名称。请有人帮我解决这个问题..帮我把我的文件包括在速度中。

标签: velocity

解决方案


推荐阅读