package com.smile.jdo.test;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
public class VMTest {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
VelocityEngine engine = new VelocityEngine();
engine.init();
Template tm = engine.getTemplate("vmhello.vm");
VelocityContext context = new VelocityContext();
//data
List<String> list = new ArrayList<String>();
list.add("test1");
list.add("pande");
list.add("school");
context.put("list", list);
StringWriter writer = new StringWriter();
tm.merge(context, writer);
System.out.println(writer.toString());
}
}
<html>
<body>
#foreach($business in $list)
$business
#end
</body>
</html>