1. Macros (macro)
wording :
< #macro page URL page masksize=5>
< #if (number = = pages) >
<li><a href= "javascript:void (0);" > Next </a></li>
<li><a href= "javascript:void (0);" > Last </a></li>
< #else >
<li><a href= "${buildpageurl (url2,page.pagenum+1,page)}" > (note: This place can directly call the function in the FTL where the macro is located) next page </a ></li>
<li><a href= "${buildpageurl (Url2,page.pages,page)}" > Last </a></li>
</#if >
</#macro >
Introduction Method: < #import "/USER/COMMON/MACRO/PAGE.FTL" as PG >
Invocation Mode:< @pg. Page url= "${queryurl}" Page=page masksize=10/>
2. Functions (function)
notation:
< #function buildpageurl URL pagenum data>
< #assign Pageurl = "${url}?pagenum=${pagenum}&pagesize=${data.pagesize}" >
< #return pageurl/>
</#function >
Introduction Method:< #include "/USER/COMMON/MACRO/DATE.FTL"/>
Invocation Mode:${buildpageurl (url2,page.pagenum+1,page)}
3. Different places
< #return the use of/>, the introduction method, the calling method are different.
Macro: Can be returned early, such as < #return/>
But not < #return 1> A macro cannot return a value
Macro, the main role is to splice the content, the macro inside the string display, return value is meaningless.
functions : Unlike macros, they are called directly${buildpageurl (Url2,page.pagenum+1,page)} executes the function.
The return value is the most critical result, not to display the string content inside the function.
---------------
Add that the function is defined in the FTL where the macro is located, and the function can be used directly in the macro.
Freemarker the use and difference of macros and functions