Intro
This post
will discuses the simple freemarker syntax's by relating them with
relevant Java syntax's.
To read this you need to have a basic idea
about freemarker
For more information please refer
[Freemarker
Manual]http://freemarker.sourceforge.net/docs/dgui_template_exp.html
Freemarker
Eclipse Plugin
[Update Site
]http://download.jboss.org/jbosstools/updates/stable/helios/
Declare
variables
Java
String str = “Test”;
FM
<#assign str = “Test” >
All other data types can be handled using
assign key word
<#assign isValidate =false >
<#assign totalvalue = 150.2 >
IF ELSE Statements
Ex 1.
Java
If(isValidate){
…......
}
FM
<#if isValidate >
…...
</#if>
Ex
2.
Java
if(totalvalue ==
100){
.........
}
<#if
totalvalue == 100 >
..…...
</#if>
Ex
3.
Java
if(totalvalue ==
100){
}else if(totalvalue == 50){
}else{
}
<#if
totalvalue == 100 >
….
<#elseif>
…...
<#else>
…...
</#if>
Ex
4.
Java
if(value!=null){
}
FM
<#if totalvalue ?? >
…...
</#if>
Iterations
Ex 1.
Java
//
bookList is a java.util.List instance or array
for(Book book :bookList){
…..
}
FM
<#list bookList as book>
</#list>
Ex 2.
Java
String titleList = "Mr,Mrs,Miss";
for (String title : titleList.split(",")) {
System.out.println(title);
}
FM
<#assign
titleList="Mr,Mrs,Miss">
<#list
titleList?split(",") as title>
${title}
</#list>
Ex
3.
Java
for(int
no=0;no<=20;no++){
.....
}
FM
<#list 0..20 as no>
</#list>
Saturday, 3 November 2012
freemarker syntax vs Java syntax
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment