2012-09-12 5 views
1

가 host.machine == 1 다음 조치 = 설정 다른 조치 = I는 다음과 같은 출력을 원하는I가 통합 할리스트의

을 만들면 IF-다른리스트 (범위) 프리 마커 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> ... "??" ... "+" ...**

답변

0

제 2 일 $에는 특별한 의미가 없기 때문에 안에 FreeMarker 식 (문자열 리터럴 안을 제외하고)이 맞습니다. ${expression}정적 텍스트 (또는 문자열 리터럴)에 표현식 값을 삽입하는 데에만 사용됩니다. 오류 메시지는 변수에 machine 또는 null이라는 하위 변수가 없음을 의미합니다. 마지막 경우에는 host.machine!0과 같은 기본값을 지정해야합니다.

BTW

이 :

<#if host.machine == 1><#assign action="Set"><#else><#assign action="Create"></#if>Type:Machine;Action:${action};

은 다음과 같이 쓸 수있다 :

Type:Machine;Action:<#if host.machine == 1>Set<#else>Create</#if>;

+0

오른쪽. 잘못된 경우 (기계/기계) 때문이었습니다. 유형 : 기계; 작업 : <# if host.Machine == 1> 집합 <#else>을 작성하십시오. – ReneHH

관련 문제