zl程序教程

您现在的位置是:首页 >  后端

当前栏目

java Velocity 同时初始化两个 Engine 实例详解编程语言

JAVA实例编程语言 详解 两个 初始化 同时 Engine
2023-06-13 09:20:29 时间
import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; public class VelocityEngineTest { private static final String TEMPLATE_NAME = "VelocityEngineTest.vm"; public static void main(String[] args) throws Exception { Properties p1 = new Properties(); p1.put("resource.loader", "file"); p1.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); p1.put("file.resource.loader.path", "./src/ve1"); Properties p2 = new Properties(); p2.put("resource.loader", "file"); p2.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); p2.put("file.resource.loader.path", "./src/ve2"); //now create the engines VelocityEngine ve1 = new VelocityEngine(); ve1.init(p1); VelocityEngine ve2 = new VelocityEngine(); ve2.init(p2); // now get the output for each engine writeTemplateOutput(ve1); writeTemplateOutput(ve2); public static void writeTemplateOutput(VelocityEngine ve) throws Exception { Template t = ve.getTemplate(TEMPLATE_NAME); Writer writer = new StringWriter(); t.merge(new VelocityContext(), writer); System.out.println(writer.toString()); }

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10472.html

cjava