1、判断变量是否存在
<#if userName??> 判断userName是否存在,为null和没这个变量都代表不存在
2、整数转化为字符串,字符串转化为整数
${xx?string} //字符串
${xx?number}//整数
3、在比较运算符的两端如果不是同一种数据类型,freemarker会报错
a=1,b=”1″ <#if a==b??>这个时候就会报错
改成这样:<#if a?string==b??>
4、当一个变量为null或者不存在时,直接取这个变量的值会报错
userName=null;
${userName}:这样写就会报错
${userName!”}:这样写ok,代表如果不存在给个默认值空字符串
但是${user.userName}这种情况下user为null,只能这样写
${(user.userName)!”}
5、获取字符串的长度
<#if user.userName?length lt 8>
6、获取集合的大小
<#if userList?size lt 8>
7、保留两位有效数字
${x?string(“0.##”)}
8、设置上下文路径
<#assign ctxPath=request.contextPath>
9、集合遍历
<div style=”overflow-y:auto;height:300px”>
<table border=”0″ cellspacing=”0″ cellpadding=”0″ class=”success-big-table”>
<tr>
<th ><input type=”checkbox” id=”selectAll” name=”selectAll” οnclick=”selectAll(this)”/></th>
<th >用户名</th>
<th >地址</th>
<th >年龄</th>
</tr>
<#if page?? && page.list?? &&page.list?size gt 0>
<#list page.list as user>
<tr>
<td>
<input type=”checkbox” name=”checkbox” value=”${user.userName!”}”/>
</td>
<td>${user.userName!”}</td>
<td>${user.addreee!”}</td>
<td>${user.age!”}</td>
</tr>
</#list>
<#else>
<tr>
<td colspan=”4″>查询无结果</td>
<tr>
</#if>
</table>
</div>
[/color][/size][/b]