首頁  >  文章  >  後端開發  >  velocity第11個應用範例---null處理

velocity第11個應用範例---null處理

黄舟
黄舟原創
2017-01-17 11:07:391189瀏覽

如果不做處理,會原樣輸出 
$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

以上就是velocity第11個應用範例--第11個應用範例--第11個應用範例--第11個應用範例--第11個應用範例--第11個應用範例--第11個應用範例--第11個應用範例--第11個應用範例-null處理的內容,更多相關內容請關注PHP中文網(www.php.cn)!


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn