IT TIP

Freemarker에서 null 값 처리

itqueen 2020. 10. 28. 21:20
반응형

Freemarker에서 null 값 처리


nullFreemarker에서 값 을 처리하는 방법은 무엇입니까? null데이터에 값이 있을 때 템플릿에서 몇 가지 예외가 발생 합니다.


??테스트 연산자를 사용할 수 있습니다 .

이것은 객체의 속성이 null이 아닌지 확인합니다.

<#if object.attribute??></#if>

이것은 객체 또는 속성이 null이 아닌지 확인합니다.

<#if (object.attribute)??></#if>

출처 : FreeMarker 매뉴얼


freemarker 2.3.7부터 다음 구문을 사용할 수 있습니다 .

${(object.attribute)!}

또는 속성이 null다음과 같을 때 기본 텍스트를 표시하려는 경우 :

${(object.attribute)!"default text"}

다른 방식으로 작동한다고 생각합니다

<#if object.attribute??>
   Do whatever you want....
</#if>

object.attributeNULL이 아닌 경우 내용이 인쇄됩니다.


진술 ??끝에 연산자를 사용하십시오 <#if>.

이 예제 null는 Freemaker 템플릿에서 두 목록의 값 을 처리하는 방법을 보여줍니다 .

List of cars:
<#if cars??>
    <#list cars as car>${car.owner};</#list>
</#if>
List of motocycles:
<#if motocycles??>
    <#list motocycles as motocycle>${motocycle.owner};</#list>
</#if>

참고 URL : https://stackoverflow.com/questions/13950289/handling-null-values-in-freemarker

반응형