출처 : http://www.ologist.co.kr/414
과거에는 velocity가 주로 템플릿 엔진으로 사용이 됐는데, 최근에는 webwork와 함께 FreeMarker가 주목을 많이 받고 있는듯 하다.
What is FreeMarker?
FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.

Ubiquitous Language : 용어정리를 해보자
- We say that the output is created by merging a template and a data model
- Files like this are called templates.
Templates
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<h1>
Welcome ${user}<#if user = "Big Joe">, our beloved leader</#if>!
</h1>
<p>Our latest product:
<a href="${latestProduct.url}">${latestProduct.name}</a>!
</body>
</html>
Data Model : the data model is basically a tree

![]() |
![]() |
![]() |
![]() |
|
Directive
* 조건문만 알면 어떤 랭귀지라도 대강 코딩할 수 있죠? 다음과 같은 syntax입니다.
Synopsis
...
<#elseif condition2>
...
<#elseif condition3>
...
...
<#else>
...
</#if>
* 기대하고 기대하는 loop사용하는 방법
<#list SequenceVar as variable>repeatThis</#list>
<p>And BTW we have these fruits:
<ul>
<#list whatnot.fruits as fruit>
<li>${fruit}
</#list>
<ul>
* include
![]() |
![]() |
![]() |
![]() |
|
* Using directives together : 함께 사용할 수도 있슴
![]() |
![]() |
![]() |
![]() |
|
ouput을 만들기 위한 샘플코드
final Writer out = new StringWriter();
Configuration cfg = new Configuration();
cfg.setClassicCompatible(false);
cfg.setClassForTemplateLoading(getClass(), THEME_TEMPLATES_CLASSPATH);
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template temp = cfg.getTemplate(fileName);
temp.process(root, out);
out.flush();
return out.toString();
}