1、引入依赖
<dependency>
<artifactId>velocity</artifactId>
<groupId>org.apache.velocity</groupId>
<version>1.7</version>
</dependency>
简单使用
// 1、设置velocity的资源加载器
Properties prop = new Properties();
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
// 2、初始化velocity引擎
Velocity.init(prop);
// 3、创建velocity容器
VelocityContext context = new VelocityContext();
context.put("name","写入的名称");
// 4、加载velocity模板文件
Template template = Velocity.getTemplate("template\\index.vm","utf-8");
// 5、合并到数据模板
FileWriter fw = new FileWriter("E:\\项目\\低代码\\模板\\index.js");
template.merge(context,fw);
// 6、释放资源
fw.close();