freemarker 常用标签 遍历 List if elseif

格式

<#if condition>
  ...
<#elseif condition2>
  ...
<#elseif condition3>
  ...
...
<#else>
  ...
 

案例

<#if x == 1>
  x is 1
 

<#if x == 1>
  x is 1
<#else>
  x is not 1
  


<#if x == 1>
  x is 1
<#elseif x == 2>
  x is 2
<#elseif x == 3>
  x is 3
  


<#if x == 1>
  x is 1
<#elseif x == 2>
  x is 2
<#elseif x == 3>
  x is 3
<#elseif x == 4>
  x is 4
<#else>
  x is not 1 nor 2 nor 3 nor 4
  

<#if x == 1>
  x is 1
  <#if y == 1>
    and y is 1 too
  <#else>
    but y is not
  
<#else>
  x is not 1
  <#if y < 0>
    and y is less than 0
  
  


变量赋值

<#assign x = "aa"/>

<#if x=="aa">

x is aa

<#else>

x not aa



遍历 list  map

<#list somelist as item>

${item}

//如果是bean

${item.title}



遍历map

 

<#list mapObj?keys ask>   <#assign item = mapObj[k]> //or <#assign item =mapObj.get(k)>  ${item.title}                                         

防止null 值 黄色警告页面

${(item.title)!"一些默认值"}

freemarker 是可以调用java 里面的方法的

如

myList 是一个list

${myList.size()}

 

将输出list 的长度

 

freemarker  大于  小于大于等于  小于等于

 

<#if x gt 1> "gt" 大于

 



 

gt     lt     gte           lte

大于  小于 大于等于 小于等于


你可能感兴趣的:(freemarker)