if判断语法的使用
<#if name=='xxx'>
hello,${name}!
<#else>
你好,${name}!
</#if>
List集合语法的使用
//遍历集合
<#list studentList as student>
...
</#list>
//获取集合的下标(索引值)
${student_index+1}
//是否存在下一个对象,存在返回true,反之返回false
<#if student_has_next>...</#if>
map集合语法的使用
//遍历集合
<#if scores?exists>
<#list scores?keys as key>
key:${key};value:${scores.get(key)}
</#list>
</#if>
空值处理运算符
Freemarker对空值的处理非常严格,Freemarker的变量必须有值,没有被赋值的变量就会抛出异常。
!:指定缺失变量的默认值;
??:判断某个变量是否存在。
用法:
${variable!}:没有给定默认值,默认为空字符串,长度为零的集合。
${variable!defaultValue}:给定一个默认值,不要求默认值的类型,可相同也可不同。
//该变量存在返回true,否则返回false
<#if variable??>
...
</#if>