velocity第11个应用例子---null处理
2015-07-22 15:30
239 查看
如果不做处理,会原样输出
$title
这不是我们期望的
我们希望输出空字符串,应该这样做:$!title
// 2Create a Context object
VelocityContextcontext = new VelocityContext();
// 3 Addyou data object to this context
context.put("title",null);
// 4Choose a template
Templatetemplate = Velocity.getTemplate("null.vm");
// 5Merge the template and you data to produce the output
StringWritersw = new StringWriter();
BufferedWriterbufferWriter = new BufferedWriter(sw);
template.merge(context,bufferWriter);
bufferWriter.flush();
System.out.println(sw.toString());
null.vm
$title
=====
$!title
如果不做处理,会原样输出
$title
这不是我们期望的
我们希望输出空字符串,应该这样做:$!title
// 2Create a Context object
VelocityContextcontext = new VelocityContext();
// 3 Addyou data object to this context
context.put("title",null);
// 4Choose a template
Templatetemplate = Velocity.getTemplate("null.vm");
// 5Merge the template and you data to produce the output
StringWritersw = new StringWriter();
BufferedWriterbufferWriter = new BufferedWriter(sw);
template.merge(context,bufferWriter);
bufferWriter.flush();
System.out.println(sw.toString());
null.vm
$title
=====
$!title
相关文章推荐
- 设计模式之抽象工厂模式
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
- WOSA/3.10 学习总结
- velocity第10个应用例子---输出到文件
- 【算法学习笔记】82.素数生成 数据范围利用 SJTU OJ 1020 分解质因数
- B - The Suspects -poj 1611
- 【连载】Maven系列(三) 进阶
- iOS中assign、copy 、retain等关键字的含义
- Sqlyog11注册码\下载地址
- hdu 1829 A Bug's Life(分组并查集)
- 多校I 1001
- 【BLE】CC2541之解析协议栈的晶振初始化过程
- POJ1068 Parencodings
- LoadLibrary失败
- crm创建报告补充导航
- 平衡的括号(栈)
- C#+Socket客户端断线重连的解决办法
- CodeForces 55D Beautiful numbers (数位DP)
- spring事物管理
- velocity第9个应用例子 ---格式化日期