【其他】【freemarker】【1】遇到的问题

前言:

1,空值导致页面报异常,Error executing FreeMarker template,The following has evaluated to null or missing

 

正文:

1,空值导致页面报异常,Error executing FreeMarker template,The following has evaluated to null or missing

原因:页面存在判断条件<#if user>,当user不存在时则报错。需写为<#if user??>,或者更改后端的FreeMarker配置。

注:我使用的时候是更改配置没有生效,还是要前端再做控制,这里写出来仅做参考

<!-- FreeMarker配置 -->
<bean id="freemarkerConfig"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/template/" />
        <property name="freemarkerSettings">
            <props>                
                <prop key="classic_compatible">true</prop><!--用于解决前端报空指针问题-->
                <prop key="defaultEncoding">utf-8</prop><!-- 设置默认的编码方式,原先是GBK,需要设置成utf-8 -->
                <prop key="template_exception_handler">rethrow</prop>
            </props>
        </property>
    </bean>

参考博客:

freemarker的classic_compatible设置,解决报空错误 - Weagle - 博客园
https://www.cnblogs.com/Weagle/p/5417947.html

posted @ 2019-05-26 23:25  花生喂龙  阅读(276)  评论(0编辑  收藏  举报