异常如下:
2019-09-05 17:47:54.941 |-ERROR [http-nio-8089-exec-7] freemarker.runtime [59] -| Error executing FreeMarker template
freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
==> info.url [in template "admin/wechatPublic/edit.ftl" at line 27, column 98]
----
Tip: It's the step after the last dot that caused this error, not those before it.
----
Tip: If the failing expression is known to be 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: ${info.url} [in template "admin/wechatPublic/edit.ftl" at line 27, column 96]
----
at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:134)
at freemarker.core.EvalUtil.coerceModelToTextualCommon(EvalUtil.java:451)
at freemarker.core.EvalUtil.coerceModelToStringOrMarkup(EvalUtil.java:374)
at freemarker.core.DollarVariable.calculateInterpolatedStringOrMarkup(DollarVariable.java:96)
at freemarker.core.DollarVariable.accept(DollarVariable.java:59)
at freemarker.core.Environment.visit(Environment.java:327)
at freemarker.core.Environment.visit(Environment.java:333)
at freemarker.core.Environment.process(Environment.java:306)
at freemarker.template.Template.process(Template.java:386)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:367)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:284)
at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:234)
。。。。。。。
解决办法:
1.配置 FreeMarker 时
<!-- freemarker的配置 -->
<bean id="freeMarkerConfigurer" class="com.biomatch.qadm.util.ShiroTagFreeMarkerConfigurer">
<property name="preferFileSystemAccess" value="false" />
<property name="templateLoaderPath" value="classpath:/view/" />
<property name="defaultEncoding" value="UTF-8" />
<property name="freemarkerSettings">
<props>
<!--用于解决前端报空指针问题-->
<prop key="classic_compatible">true</prop>
<prop key="template_update_delay">10</prop>
<prop key="locale">zh_CN</prop>
<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
<prop key="date_format">yyyy-MM-dd</prop>
<prop key="number_format">#.##</prop>
</props>
</property>
<property name="freemarkerVariables">
<map>
<entry key="ctx" value="/queue-admin"></entry>
<!-- <entry key="test" value="'test'"></entry> -->
</map>
</property>
</bean>
添加:
<!--用于解决前端报空指针问题-->
<prop key="classic_compatible">true</prop>
2.前端判断null修改
<input type="text" class="form-control" id="url" value=${info.url}>
改为
<input type="text" class="form-control" id="url" value=${(info.url)?default('')}>