如何在freemarker中将null设置为变量 [英] How to set null to a variable in freemarker
问题描述
在任何问题上我都找不到与此相关的任何东西,这确实很基本,但是我无法弄清楚.
I can't find anything related to this on any question, and it is something really basic, but I can't figure it out.
所以我的问题是我不知道如何在freemarker中将null设置为变量. 示例:
So my problem is that I don't know how to set null to a variable in freemarker. Example:
${hi!"bye"} <#-- Prints "bye" because hi is undefined -->
<#assign hi="hi"> <#-- Sets a value to the var hi -->
${hi!"bye"} <#-- Prints "hi" because hi has a value -->
<#assign hi=null> <#-- This does not work but is what I am looking for -->
${hi!"bye"} <#-- I want it to print "bye" because hi should be undefined -->
我有这个问题,因为如果特定项目的某些逻辑通过验证,我会遍历一个列表并设置一个var,然后检查该var是否存在,但是如果第一个项目创建了var,那么我将设置var列表中其余项目.
I have this problem because I iterate over a list and set a var if some logic to the specific item validates, and then check if the var exists, but if the first item creates the var, then I will have the var set for the rest of the items in the list.
推荐答案
不,没有"unssign",在FreeMarker中也没有null
的概念(至少到2.4.0,但这还是很遥远).它只有缺失的变量(从技术上讲可能是null
,也许根本不存在)和那些在那里.我真的不明白为什么您需要这样做.您可以显示这种情况的简化示例吗?
No, there's no "unassign", nor the concept of null
exists in FreeMarker (until 2.4.0 at least, but that's far away anyway). It only have missing variables (maybe technically a null
, maybe doesn't exist at all) and those that are there. I don't really get why is that needed in your case. Can you show a simplified example of the situation?
这篇关于如何在freemarker中将null设置为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!