Templates Freemarker(如果列表中有其他项)(范围)

Templates Freemarker(如果列表中有其他项)(范围),templates,freemarker,template-engine,Templates,Freemarker,Template Engine,在一个列表中,我想合并一个if host.machine==1,然后action=Set else action=Create 我想要以下输出 类型:机器;动作:设定;属性[名称:machine1~NodeManager.ListenAddress:10.104.17.70~NodeManager.ListenPort:5558] 类型:机器;行动:创造;属性[名称:machine2~NodeManager.ListenAddress:10.104.17.71~NodeManager.Liste

在一个列表中,我想合并一个if host.machine==1,然后action=Set else action=Create

我想要以下输出
类型:机器;动作:设定;属性[名称:machine1~NodeManager.ListenAddress:10.104.17.70~NodeManager.ListenPort:5558]
类型:机器;行动:创造;属性[名称:machine2~NodeManager.ListenAddress:10.104.17.71~NodeManager.ListenPort:5558]

我的数据

主机:[{“name”:“trfuoemlpa004v”,“node”:0,“server”:1,“Machine”:1,“ManagedPort”:“7002”,“SSLPort”:1081},
{“name”:“trfuoemlpa007v”,“node”:1,“server”:2,“Machine”:2,“ManagedPort”:“7002”,“SSLPort”:1081}]

我制作了不同的模板,但都失败了:

(一)
类型:机器;动作:${Action};属性[名称:${host.machine}~NodeManager.ListenAddress:${host.Name}~NodeManager.ListenPort:${NodeManager端口}]

**freemarker.core.ParseException:在中第8行第40列遇到“}”
J2EE.properties。
正在期待一个“>”。。。
"." ...
"[" ...
"(" ...
"?" ...
"!" ...
...
"??" ...
“+”…**

(二)
Type:Machine;Action:${Action};Attributes[Name:${host.Machine}~NodeManager.ListenAddress:${host.Name}~NodeManager.ListenPort:${NodeManager}]

**freemarker.core.InvalidReferenceException:表达式host.machine未定义**

(三)

**freemarker.core.ParseException:在中第8行第40列遇到“}”
J2EE.properties。
正在期待一个“>”。。。
"." ...
"[" ...
"(" ...
"?" ...
"!" ...
...
"??" ...

“+”。错误消息表示
host
变量没有名为
machine
的子变量,或者它是
null
。在最后一种情况下,您必须为它指定一些默认值,如
host.machine!0

顺便说一句,这是:

类型:机器;操作:${Action};

可以这样写:


类型:Machine;操作:SetCreate;

正确。这是因为它的大小写错误(Machine/Machine)。类型:Machine;操作:SetCreate;