Home>Article>Backend Development> The 11th application example of velocity---null processing
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 (m.sbmmt.com)!