字符串:exp?substring(begin,end) exp?substring(begin) ${'abc'?substring(0,1)} => a ${'abc'?substring(1)} =>bc 首字母大寫(小寫):exp?cap_first exp?uncap_first exp?capitalize ${'abc'?cap_first} =>Abc ${'my nAme is ws'?capitalize} => My Name Is Ws ${ "MY nAme Is Ws"?lower_case} =>my name is ws 日期:date,time,datetime ${ "12/25/2013" ?date( "MM/dd /yyyy" )}<br/> ${"12:25:20"?time( "HH:mm:ss")}<br/> ${"12/25/2013 12:25:20"? datetime("MM/dd/yyyy HH:mm:ss")} <br/> 以...結尾/開頭:end_with start_with ${ "kings"?ends_with(" ings" )} =>true 索引位置:index_of ${ "kings"?index_of(" ings" )} =>1 java/js字符串轉意:j_string/js_string ${ 'kings name is "王勝"' ?j_string}<br/> =>kings name is \"王勝\" 最後的索引位置:last_index_of("str"[,bigestIndex]) ${ 'kings name is king' ?last_index_of("king")} =>14 ${'kings name is king'?last_index_of( "king" ,10)} =>0 字符串長度:length 距左邊:left_pad 左填充 right_pad 右填充 [ ${"ws" ?left_pad(8,"-")} ] => [------ws] [ ${ "ws" ?right_pad(8, "-")} ] => [ws------] 包含:contains ${ "ws"?contains("w" )} 匹配:matchs 和groups ${"kii" ?matches("ki*" )}<br/> true ${"kigi" ?matches("ki*" )}<br/> 無內容 { "kigi"?matches(" ki(.?)*" )}<br/> true <#assign regs ="king/007/ ws"?matches("(\\w*)/(\\d*)/(\\w*)" )> <#list [1,2,3] as v> == ${regs ?groups[v]}== </#list><br/> =>==king== ==007== ==ws== 替代:replace ${'kings007'?replace("007","008")} =>kings008 ${ 'kings007'?replace("" ,",")} =>,k,i,n,g,s,0,0,7, 切割:split <#assign vs = "我是中國人" ?split("是")> <#list vs as v> ${v} </#list> =>我 中國人 去空格:trim " ${" i am ws "?trim}" =>"i am ws" 處理數字 數字轉字符:string ${1.234?string( "0.##")} => 1.23 ${1.234?string( "0.####" )} => 1.234 ${1.85?string( "0.#")} =>1.8 若是是5 四捨五入到偶數的鄰居 ${1.86?string( "0.#")} =>1.9 數字舍入處理:round(知足.5就進位)、floor、ceilling 處理序列 序列包含:seq_contains <#assign sq=["a" ,16]> ${sq ?seq_contains("16" )?string("true", "false")} =>false ${sq ?seq_contains(16 )?string( "true", "false" )} =>true 序列大小:size 序列長度: ${lists?size} 序列反轉:reverse 原序列:中國人,美國人,德國人 序列反轉第0個元素: ${lists?reverse[0]} =>,德國人 序列排序:sort sort_by(exp?sort_by("chars"[,"chars1"])) <#local listss=lists?sort> <#list listss as ll>${ll}</#list> 德國人,美國人,中國人 序列區塊:chunk <table cellpadding ="0" cellspacing ="1" width="500px;" border= "1px solid #ccc"> <#assign sequen =["a" ,"b", "c","d" ,"e", "f","g" ,"h", "i"]> <#list sequen?chunk(4,"-" ) as row> <tr> <#list row as s> <td>${s}</td> </#list> </tr> </#list> </table> 效果 處理Map <#assign ma={"name" :"王勝", "age":23}> <#assign keys=ma?keys> <#list keys as key> ${key}<==>${ma[key]} </#list> ==>name<==>王勝 age<==>23 處理JSON <#local data=menuJson? eval /> 處理求值 ${ "1+2"?eval} 處理是否含有內容 ${ma?has_content} 字符串轉爲freemark模板:interpret <br/>=======字符串轉爲freemark模板======<br/> <#assign xx=["aa" ,"bb" ,"cc"]> <#assign templ =r"<#list xx as yy>${yy}</#list>"> <#--r用於排除解釋${yy}--> <#assign myinterpret =templ?interpret > <@myinterpret></@myinterpret> <br/>=======字符串轉爲freemark模板====== <br/>