velocity第七个应用例子----在模板中进行赋值
2015-07-22 15:25
465 查看
//2 Create a Context object
VelocityContext context = newVelocityContext();
//3 Add you data object to this context
context.put("name", "老毕");
//4 Choose a template
Template template =Velocity.getTemplate("template7.vm");
//5 Merge the template and you data toproduce the output
StringWriter sw = new StringWriter();
template.merge(context, sw);
sw.flush();
System.out.println(sw.toString());
模板
数组赋值
#set($ints=["第一个","第二个","第三个"])
#foreach($entryin $ints)
$entry
#end
===
#set($ints=[1..10])
#foreach($int in $ints)
$int
#end
===
${name}
===============
#set($name="军旗")
$name
===
#set($condition=true)
#set($condition=false)
#if($condition)
成立
#else
不成立
#end
====
//2 Create a Context object
VelocityContext context = newVelocityContext();
//3 Add you data object to this context
context.put("name", "老毕");
//4 Choose a template
Template template =Velocity.getTemplate("template7.vm");
//5 Merge the template and you data toproduce the output
StringWriter sw = new StringWriter();
template.merge(context, sw);
sw.flush();
System.out.println(sw.toString());
模板
数组赋值
#set($ints=["第一个","第二个","第三个"])
#foreach($entryin $ints)
$entry
#end
===
#set($ints=[1..10])
#foreach($int in $ints)
$int
#end
===
${name}
===============
#set($name="军旗")
$name
===
#set($condition=true)
#set($condition=false)
#if($condition)
成立
#else
不成立
#end
====
相关文章推荐
- java理论之java数组和集合
- string相关
- 学法语的你伤不起之吐槽各种语言
- [ActionScript 3.0] 判断XML属性是否存在
- iOS开发笔记-Xcode添加pch文件
- [RMQ+二分] 2015多校联合第一场 Assignment
- 假如你喜欢一个程序员小伙
- C++学习之旅——结构体和联合体的区别,以及数据对齐方式影响内存大小
- 高可用Hadoop平台-Flume NG实战图解篇
- velocity第五个应用例子---获得当前迭代的索引
- Java反射实例 自己用于记录
- Android APP开发需求文档范本
- 渐变的参数
- [转]AndroidDevTools简介
- 洛谷-07敦刻尔克大撤退-[再也不坑]【二战2】二战系列2:狼烟四起
- dp与px之间的关系转换方法
- 【版本控制】Github for Windows客户端的使用
- HTML5图片 拖放上传
- Linux文件目录详解
- linux 中特殊符号用法详解