解决The following has evaluated to null or missing的问题

  • Post author:
  • Post category:其他


解决The following has evaluated to null or missing的问题

今天早上遇到了访问页面是,抛出的一个问题

The following has evaluated to null or missing: ==> optionItem[’’+parameters.listValue] [in template “template/haiyisoft/drop/drop.ftl” at line 112, column 58] —- Tip: It’s the final [] step that caused this error, not those before it. —- 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: #assign itemValue = optionItem[“” + p… [in template “template/haiyisoft/drop/drop.ftl” at line 112, column 37] —- – Class: freemarker.core.InvalidReferenceException File: InvalidReferenceException.java Method: getInstance Line: 134 – freemarker/core/InvalidReferenceException.java:134:-1

首先我对这个错误进行分析,关键词:

  1. optionItem[’’+parameters.listValue]
  2. If the failing expression is known to legally refer to something that’s sometimes null or missing
  3. [in template “template/haiyisoft/drop/drop.ftl” at line 112, column 37

    看到这里,我一开始因为是前天jsp页面进行赋值是出现了错误,然后通过排查,发现jsp没有问题,然后就把注意力转向了drop.ftl,因为该项目是使用Freemarker模板技术进行赋值的,所以我就打开了drop.ftl文件,查看112行

    在这里插入图片描述

    看完恍然大悟,发现optionItem[’’+parameters.listValue]可能是为null,所以在赋值前需要进行检验,检查该值是否为空的判断

    因此我就在112代码中添加了判断

    在这里插入图片描述

    就完美的解决了该问题



版权声明:本文为weixin_37541878原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。