问题
ERROR 792 --- [nio-8080-exec-2] freemarker.runtime : Error executing FreeMarker template
freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> recomHouses [in template "homepage/index.ftl" at line 107, column 27]
----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like 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 parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: #list recomHouses as house [in template "homepage/index.ftl" at line 107, column 20]
截图:
原因
index.ftl文件中的这个值为空
解决办法
1、在此处添加if判断语句。就像日志提示的那样
<#if myOptionalVar??>when-present<#else>when-missing</#if>
2、在application.properties添加spring.freemarker.settings.classic_compatible=true
一句即可。【推荐】