首页 > 其他 > 详细

FreeMarker template error

时间:2015-12-12 02:13:00      阅读:499      评论:0      收藏:0      [点我收藏+]

在使用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‘}

?

参考附件

?

?

FreeMarker template error

原文:http://hw1287789687.iteye.com/blog/2263466

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!