您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: