gpt4 book ai didi

freemarker - 如何在 freemarker ( .ftl ) 中转储对象

转载 作者:行者123 更新时间:2023-12-01 11:27:56 25 4
gpt4 key购买 nike

有没有办法如何转储整个对象并将其写在某个地方?

喜欢:var_dump()在 php 中console.log在JS中

我找到了类似 list 的东西,所以我在下面尝试这样的事情:

<#list calculation as c>
${c}
</#list>

但是模板会出错。我appriciate任何建议!

最佳答案

这取决于您正在迭代的对象类型。您可以检查变量的数据类型,然后适本地输出它(引用:http://freemarker.incubator.apache.org/docs/ref_builtins_expert.html#ref_builtin_isType)

这里有些例子:

<#if calculation?is_sequence>
<#list calculation as c>
${c}
</#list>
<#elseif calculation?is_hash_ex>
<#list calculation?keys as key>
${key} - ${calculation[key]}
</#list>
<#elseif calculation?is_string>
${calculation}
</#if>

看看 https://github.com/ratherblue/freemarker-debugger/blob/master/debugger.ftl有关转储数据的更多示例

关于freemarker - 如何在 freemarker ( .ftl ) 中转储对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35702520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com