在使用freemarker的过程当中常常会见到以下错误:html
- 11 十二月 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: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??
模板代码以下:express
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>freemarker demo</title>
- </head>
- <body>
- ${username} <br />
- ${age}<br />
- ${sex}
- </body>
- </html>
根本缘由: sex没有设置值,因此报错lua
解决方法:spa
在未声明的变量后面增长叹号xml
也能够设置默认值,在叹号后面增长默认值htm