FreeMarker template error
在使用freemarker的过程中经常会见到如下错误:
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)??
模板代码如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>freemarker demo</title> </head> <body> ${username} <br /> ${age}<br /> ${sex} </body> </html>
根本原因: sex没有设置值,所以报错
解决方法:
在未声明的变量后面增加叹号
${sex!}
也可以设置默认值,在叹号后面增加默认值
${sex!'abc'}
参考附件
相关推荐
81314797 2020-11-18
89314493 2020-11-03
81941231 2020-09-17
thisisid 2020-09-09
如狼 2020-08-15
82384399 2020-06-16
86384798 2020-05-12
80183053 2020-05-02
86384798 2020-04-26
86384798 2020-04-11
rionchen 2020-04-09
86384798 2020-04-07
86384798 2020-04-04
80183053 2020-03-07
87201943 2020-03-06
83961233 2020-02-26
87201943 2020-02-21