这篇文章译自javaWord上面的《Start up the velocity Template Engine》
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
public class HelloWorld
{
public static void main( String[] args )
throws Exception
{
/* first, get and initialize an engine */
VelocityEngine ve = new VelocityEngine();
ve.init();
/* next, get the Template */
Template t = ve.getTemplate( "helloworld.vm" );
/* create a context and add data */
VelocityContext context = new VelocityContext();
context.put("name", "World");
/* now render the template into a StringWriter */
StringWriter writer = new StringWriter();
t.merge( context, writer );
/* show the World */
System.out.println( writer.toString() );
}
}
本文介绍Velocity模板引擎的基本使用方法,包括如何创建模板文件和对应的Java程序来显示动态内容。通过Hello World示例展示了Velocity的主要特点和优势。
310

被折叠的 条评论
为什么被折叠?



