How to Solve FreeMarker template error

In the process of using freemarker, the following errors are often seen:

11 Dec 2015 15:53:09,674 ERROR freemarker.runtime:98 - Error executing FreeMarker template  
FreeMarker template error:  
The following has evaluated to null or missing:  
==> sex  [in template "freemarker3.html" at line 10, column 3]  
Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (!myDefault, (


The template code is as follows:

<!DOCTYPE html>  
<meta charset="UTF-8">  
<title>freemarker demo</title>  
${username} <br />  
${age}<br />  

 Root cause: sex is not set, so an error is reported


Add an exclamation mark after undeclared variables



 You can also set the default value, add the default value after the exclamation mark


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *