【freemarker】freemarker数值处理&指令

1 数值处理


<#--布尔转字符串-->
<h4>布尔</h4>
${flag?c} <br>
${flag?string}<br>
${flag?string("dd","fff")}<br>

<#--日期-->
<h4>日期</h4>
${date?date} <br>
${date?time} <br>
${date?datetime} <br>
${date?string("dd.MM.yyyy, HH:mm")} <br>

<#--日期-->
<h4>数值</h4>
${data01} <br>
${data01?string.currency} <br>
${data01?string["0.#"]} <br>

<#--string-->
<h4>字符串</h4>
${string01} <br>
${string01?substring(0,3)} <br>
${string01?substring(1)} <br>
${string01?starts_with("q")?c} <br>

<#--序列-->
<h4>String[]输出</h4>
${stringDemo?size} <br>
${stringDemo?first} <br>
<#list stringDemo as stringD>
${stringD}
</#list><br>

<#list stringDemo?sort as stringD>
${stringD}
</#list><br>

<#list listDemo as stringD>
${stringD}
</#list><br>

<#list userList as stringD>
${stringD}<br>
${stringD.userId}<br>
${stringD.userName}<br>
${stringD.userAge}<br>
</#list><br>

<#--hash-->
<h4>=========hash输出============</h4>
<#list hashmapDemo?keys as stringD>
${stringD}<br>
</#list><br>
<#list hashmapDemo?values as stringD>
${stringD}<br>
</#list><br>
<#--空值处理
! 指定默认值
?? 判断存在与否-->
${msg!}<br>
${msg1!"默认000"}<br>
${(str??)?c}<br>
<#-- 自定义变量 -->
<h5> 自定义变量</h5>
<#assign uname="chen"/>
<#assign uname1="chen1" starts=["sss","sssew"]/>
<#assign user01=[]/>

${uname!}<br>
${uname1!}<br>
<#list starts as star>
${star}<br>
</#list>

<#-- 条件判断 -->
<h5> 条件判断</h5>
<#assign score=60/>
<#if score gte 20>
<b>分数大于等于20</b>
</#if>
<#if score lte 120> <b>分数小于120</b><br>
<#elseif score = 60> <b>分数等于60</b><br>
<#else> <b>其他</b><br>
</#if>

<#-- list判断 -->
<#if list??> <b>有值</b><br>
<#else> <b>其他</b><br>
</#if>

<#-- list遍历 -->
<#if user01??>
<#list user01 as user>
${user}
<#else> 没数据
</#list>
</#if>

2 指令

<#-- 自定义指令指令 无参数-->
<#macro address>
adetqwqrewrqerqwerqwer
</#macro>
<@address></@address>

<#-- 自定义指令指令 一个参数-->
<#macro queryName name>
${name}
</#macro>
<@queryName name="admin"></@queryName>

<#-- 自定义指令指令 两个参数-->
<#macro queryName1 name pwd>
${name}
</#macro>
<@queryName1 name="admin" pwd="123"></@queryName1><br>

<#macro cfb num>
<#list 1..num as i>
<#list 1..i as j>
${j}*${i} = ${i*j} &nbsp;
</#list>
<br>
</#list>
</#macro>
<@cfb 11></@cfb>

<#--宏的站位指令-->
<#macro test>
detertert
<#nested>
</#macro>

<@test>
==============
</@test>

<#--导入指令-->
<#import "commons.ftl" as com/>
<br>
<@com.cfbtest 6></@com.cfbtest>

<#--包含指令-->
<#include "test.ftl"/>
<#include "../htl.html"/>


 

上一篇:freemarker中js里面取字符串,换行导致报错的解决办法


下一篇:eclipse安装freemarker IDE插件