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

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

黄舟
Release: 2023-03-04 21:44:01
Original
1257 people have browsed it

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
Copy after login

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)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template