freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...

在使用 Freemarker 模板时遇到了 `freemarker.core.InvalidReferenceException`,错误发生在 `product.html` 的第751行。问题源于尝试访问一个为 null 或缺失的 `product` 对象。解决方法是在访问对象属性前进行空值检查,避免直接引用可能为 null 的对象。参考链接提供了解决此类异常的详细建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FreeMarker template error:
The following has evaluated to null or missing:
==> product  [in template "product.html" at line 751, column 43]

 

FreeMarker模板误差:
以下已评估为null或丢失:
=产品“模板”产品HTML“在第751行,第43栏]

----------------------------

意思是有个值为null,就是不存在,

 

 

Tip: If the failing expression is known to be legally null/missing, either specify a default value with 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 parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??

 

Tip: If the failing expression is known to be legally null/missing, either specify a default value with 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 parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??
-----------------
提示:如果没有表达是合法的空/失踪,或者指定一个默认值myoptionalvar!mydefault,或使用< #如果myoptionalvar??>在< #别的>当失踪/ # <<如果>>。(这些仅覆盖的表达;最后一步覆盖整个表达式,使用parenthessis:(myoptionvar。Foo)!mydefault,(myoptionvar。Foo)??
 
大概意思是应该进行判断,对象是否为空

 

 

 

 

 

一般出现这种异常的原因为:如果对象为空,则freemarker就会抛出这个异常。

其实解决很简单,在用对象之前先判空,不空在进行属性的获取操作即可

 

原文地址

转载于:https://www.cnblogs.com/tongs/p/7493382.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值