我编写了以下 StringTemplate 模板行:
<instance.attributes: { attr | <attr.value>}>
<instance.attributes: { attr | <if(attr.value)>skip<else>don't skip<endif> } >
如果 Instance.getAttributes().getValue()
返回的对象值是一个值为 true 的 boolean 值,则可以跳过。
这个结果
1
skip
和
0
skip
(目前我只有一个属性)
问题是什么?为什么我不明白?
0
don't skip
最佳答案
<if(attribute)>subtemplate <else>subtemplate2 <endif>
if attribute has a value or is a boolean object that evaluates to true, include subtemplate else include subtemplate2. These conditionals may be nested.
我假设 0 表示不是 false
,但某些值表明存在值并评估为 true。在将其推送到模板之前,您需要计算计算结果为 false 的 boolean 值。
关于java - 如何使用 Java StringTemplate boolean 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11741017/