Home  >  Article  >  Backend Development  >  The 11th application example of velocity---null processing

The 11th application example of velocity---null processing

黄舟
黄舟Original
2017-01-17 11:07:391189browse

If no processing is done, it will be output as it is
$title

This is not what we expect

We want to output an empty string, so we should do this: $!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

The above is the 11th application example of velocity---null processing content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn