<转>FreeMarker内置函数
一、 Sequence的内置函数
1. sequence?first 返回sequence的第一个值。
2. sequence?last 返回sequence的最后一个值。
3. sequence?reverse 将sequence的现有顺序反转,即倒序排序
4. sequence?size 返回sequence的大小
5. sequence?sort 将sequence中的对象转化为字符串后顺序排序
6. sequence?sort_by(value) 按sequence中对象的属性value进行排序
二、 Hash的内置函数
1. hash?keys 返回hash里的所有key,返回结果为sequence
2. hash?values 返回hash里的所有value,返回结果为sequence
例如:
<#assign user={“name”:“hailang”, “sex”:“man”} />
<#assign keys=user?keys />
<#list keys as key>
${key}=${user[key]}
</#list>
三、 操作字符串函数
1. substring(start,end)从一个字符串中截取子串
start:截取子串开始的索引,start必须大于等于0,小于等于end
end: 截取子串的长度,end必须大于等于0,小于等于字符串长度,如果省略该参数,默认为字符串长度。
例子:
${‘str’?substring(0)},结果为str
${‘str’?substring(1)},结果为tr
${‘str’?substring(2)},结果为r
${‘str’?substring(3)},结果为
${‘str’?substring(0,0)},结果为
${‘str’?substring(0,1)},结果为s
${‘str’?substring(0,2)},结果为st
${‘str’?substring(0,3)},结果为str
2.cap_first 将字符串中的第一个单词的首字母变为大写。
${‘str’?cap_first},结果为Str
3. uncap_first将字符串中的第一个单词的首字母变为小写。
${‘Str’?cap_first},结果为str
4. capitalize将字符串中的所有单词的首字母变为大写
${‘str’?capitalize},结果为STR
5. date,time,datetime将字符串转换为日期
例如:
<#assign date1=”2009-10-12”?date(“yyyy-MM-dd”)>
<#assign date2=”9:28:20”?time(“HH:mm:ss”)>
<#assign date3=” 2009-10-12 9:28:20”?time(“HH:mm:ss”)>
${date1},结果为2009-10-12
${date2},结果为9:28:20
${date3},结果为2009-10-12 9:28:20
注意:如果指定的字符串格式不正确将引发错误。
<转>FreeMarker内置函数的更多相关文章
- Freemarker 内置函数 数字、字符串、日期格式化用法介绍
在用FreeMarker过程中,感觉FreeMarker的字符串,日期,集合等处理能力还是很强大的,上网搜了一些资料,整理如下,以便能帮助大家更熟练的应用Freemarker完成项目开发. 一.Seq ...
- freemarker内置函数和用法
原文链接:http://www.iteye.com/topic/908500 在我们应用Freemarker 过程中,经常会操作例如字符串,数字,集合等,却不清楚Freemrker 有没有类似于Jav ...
- Freemarker中遍历List以及内置函数使用
在Freemarker应用中经常会遍历List获取需要的数据,并对需要的数据进行排序加工后呈现给用户. 那么在Freemarker中如何遍历List,并对List中数据进行适当的排序呢?一. Free ...
- FreeMarker惯用内置函数
1.sequence?first 返回sequence的第一个值. 2.sequence?last 返回sequence的最后一个值. 3.sequence?reverse 将sequence的现有顺 ...
- Entity Framework 6 Recipes 2nd Edition(11-12)译 -> 定义内置函数
11-12. 定义内置函数 问题 想要定义一个在eSQL 和LINQ 查询里使用的内置函数. 解决方案 我们要在数据库中使用IsNull 函数,但是EF没有为eSQL 或LINQ发布这个函数. 假设我 ...
- Oracle内置函数:时间函数,转换函数,字符串函数,数值函数,替换函数
dual单行单列的隐藏表,看不见 但是可以用,经常用来调内置函数.不用新建表 时间函数 sysdate 系统当前时间 add_months 作用:对日期的月份进行加减 写法:add_months(日期 ...
- python内置函数
python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...
- DAY5 python内置函数+验证码实例
内置函数 用验证码作为实例 字符串和字节的转换 字符串到字节 字节到字符串
- python之常用内置函数
python内置函数,可以通过python的帮助文档 Build-in Functions,在终端交互下可以通过命令查看 >>> dir("__builtins__&quo ...
随机推荐
- c_水程序
* ** This program reads input lines from the standard input and prints ** each input line, followed ...
- 5.6---交换整数的奇数位和偶数位(CC150)
这道题要利用101010来&. 如下答案: public class Exchange { public int exchangeOddEven(int x) { // write code ...
- 火狐浏览器,关闭ssl v3防护
某些网站,没有及时更新,导致火狐觉得有安全隐患,不给访问. --------------- Hello bcasey9090, go to about:config, copy the next bo ...
- wav转aac
//调用neroAacEnc.exe STARTUPINFO si={}; PROCESS_INFORMATION pi={};//隐藏窗口 si.cb=sizeof(si); si.dwFlags= ...
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
http://blog.csdn.net/pucker/article/details/41843511 上一篇文章<iOS 8界面自动布局系列-1>简要介绍了iOS界面布局方式的前世今生 ...
- Response.Redirect()、Server.Execute和Server.Transfer的区别
1.Response.Redirect(): Response.Redirect方法导致浏览器链接到一个指定的URL. 当Response.Redirect()方法被调用时,它会创建一个应答,应答头中 ...
- apache的httpd.conf翻译
# This is the main Apache HTTP server configuration file. It contains the 这是Apache HTTP Server的主配置文件 ...
- Django~static files (e.g. images, JavaScript, CSS)
django.contrib.staticfiles settings.py django.contrib.staticfiles is included in your INSTALLED_APPS ...
- 【Android Studio错误】 If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.
解决办法:以管理员身份运行cmd窗口,输入命令“netsh winsock reset” netsh winsock reset命令,作用是重置 Winsock 目录.如果一台机器上的Winsock协 ...
- code vs1706 求合数和(数论 素数的判定)
1706 求合数和 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 Description 用户输入一个数,然后输出 ...