helloworld.java

来自「Turbine示例」· Java 代码 · 共 52 行

JAVA
52
字号
import java.io.StringWriter;import org.apache.velocity.app.VelocityEngine;import org.apache.velocity.Template;import org.apache.velocity.VelocityContext;/** *  Simple program to demonstrate the basic  *  technique of rendering a Velocity template */public class HelloWorld{    public static void main( String[] args )        throws Exception    {        /*         *  first, get and initialize a Velocity 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() );         }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?