봉 블로그

Freemarker Tip 본문

java

Freemarker Tip

idkbj 2009. 10. 19. 11:52

request parameter 가져오기

${RequestParameters.aaa} or ${RequestParameters.['aaa']}

 

request attributes 가져오기

${Request.aaa} or ${Request.['aaa']}


Default value operator : !

그 값이 없을때 default value를 명시할수 있다.

예를 들어 mouse 에 값이 없을때
${mouse!"No mouse."}
<#assign mouse="Jerry">
${mouse!"No mouse."} 

The output will be:

No mouse.
Jerry  

또다른 예
(${mouse!})
<#assign mouse = "Jerry">
(${mouse!}) 

The output will be:

()
(Jerry)  


Escape Example:

<#escape x as x?html>
  First name: ${firstName}
  Last name: ${lastName}
  Maiden name: ${maidenName}
</#escape>  

is actually equivalent to:

  First name: ${firstName?html}
  Last name: ${lastName?html}
  Maiden name: ${maidenName?html 

null값 체킹
<#if param1??>
// param1은 null아 아니다.
</#if>

List 관련 작업
<#list list as item>
            <#if (item_index > 0)> // 2번째 item 부터... </#if>
            <#if item_has_next> // 다음 item 이 있다면... </#if>
</#list>

태그 라이브러리 사용법
http://freemarker.sourceforge.net/docs/pgui_misc_servlet.html#autoid_55

Map 처리
<#list condition.conditionValueMap?keys as key>
      ${condition.conditionValueMap[key]}
</#list>