springboot整合freemarker出现空指针异常的解决办法
问题
ERROR 792 --- [nio-8080-exec-2] freemarker.runtime                      : Error executing FreeMarker template
==> 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!myDef ault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expressi on, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----springboot是啥
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⼀句即可。【推荐】

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。