EmailDemo.java
import java.io.StringWriter; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; public class EmailDemo { public static void main( String[] args ) throws Exception { /* * first, get and initialize an engine */ VelocityEngine ve = new VelocityEngine(); ve.init(); /* * organize our data */ ArrayList list = new ArrayList(); Map map = new HashMap(); map.put("name", "Cow"); map.put("price", "$100.00"); list.add( map ); map = new HashMap(); map.put("name", "Eagle"); map.put("price", "$59.99"); list.add( map ); map = new HashMap(); map.put("name", "Shark"); map.put("price", "$3.99"); list.add( map ); /* * add that list to a VelocityContext */ VelocityContext context = new VelocityContext(); context.put("petList", list); /* * get the Template */ Template t = ve.getTemplate( "./src/email_xml.vm" ); /* * now render the template into a Writer, here * a StringWriter */ StringWriter writer = new StringWriter(); t.merge( context, writer ); /* * use the output in the body of your emails */ System.out.println( writer.toString() ); } }
email_xml.vm
<?xml version="1.0"?> <salelist> #foreach( $pet in $petList ) <pet> <name>$pet.name</name> <price>$pet.price</price> </pet> #end </salelist>
收藏
0人收藏
- 2016-01-21 09:00:44Velocity 解析 XML 数据 by arden
- 2014-08-15 19:30:04Python 解析xml(dom) by 龙堂修罗
- 2015-08-03 13:13:26C语言使用DOM解析XML by arden
- 2016-01-08 14:00:00自定义JDOM工厂类:Custom JDOM Factory by 猩猩总统
- 2016-01-10 09:16:20Digester 解析 XML 的简单一例 by amaker8
- 2013-12-05 18:22:54jQuery定时读取分析xml文件 by 猩猩总统
- 2015-11-29 09:25:23JDOM: StAX Stream Tree Viewer by 龙堂修罗
- 2015-03-29 11:34:48将数组转换为XML by 杨德伟
- 2015-08-06 10:27:46将 Scala XML 转成 Java DOM by huwei
- 2015-12-06 11:04:09SAXParser 解析 XML 时禁用外部 DTD 加载 by starstroll
- 2019-02-14 21:23:37美丽人生在线观看 by 佐助757201808
相关聚客文章