在一个列表中,我想合并一个 if host.machine == 1 then action=Set else action=Create
我想要以下输出
Type:Machine;Action:Set;Attributes[Name:machine1~NodeManager.ListenAddress:10.104.17.70~NodeManager.ListenPort:5558]<BR>
Type:Machine;Action:Create;Attributes[Name:machine2~NodeManager.ListenAddress:10.104.17.71~NodeManager.ListenPort:5558]<BR>
我的数据
hosts:[{"name": "trfuoemlpa004v", "node": 0, "server": 1, "Machine": 1, "ManagedPort": "7002", "SSLPort": 1081},
{"name": "trfuoemlpa007v", "node": 1, "server": 2, "Machine": 2, "ManagedPort": "7002", "SSLPort": 1081}]
我制作的不同模板都失败了:
1)
<#list hosts as host><#assign machine=${host.machine}><#if machine == 1><#assign action="Set"><#else><#assign action="Create"></#if>Type:Machine;Action:${action};Attributes[Name:${host.machine}~NodeManager.ListenAddress:${host.name}~NodeManager.ListenPort:${nodeManagerPort}]<BR></#list>
**freemarker.core.ParseException: Encountered "}" at line 8, column 40 in
J2EE.properties.
Was expecting one of:">" ...
"." ...
"[" ...
"(" ...
"?" ...
"!" ...
<TERMINATING_EXCLAM> ...
"??" ...
"+" ...**
2)
<#list hosts as host><#if host.machine == 1><#assign action="Set"><#else><#assign action="Create"></#if>Type:Machine;Action:${action};Attributes[Name:${host.machine}~NodeManager.ListenAddress:${host.name}~NodeManager.ListenPort:${nodeManagerPort}]<BR></#list>
**freemarker.core.InvalidReferenceException: Expression host.machine is undefined**
3)
<#list hosts as host><#if $host.machine} == 1 > ...
**freemarker.core.ParseException: Encountered "}" at line 8, column 40 in
J2EE.properties.
Was expecting one of:">" ...
"." ...
"[" ...
"(" ...
"?" ...
"!" ...
<TERMINATING_EXCLAM> ...
"??" ...
"+" ...**