Freemarker 内置函数
There is no nutrition in the blog content. After reading it, you will not only suffer from malnutrition, but also impotence.
The blog content is all parallel goods. Those who are worried about being cheated should leave quickly.
Sequence 内置函数
- sequence?first 返回sequence 的第一个值。
- sequence?last 返回sequence 的最后一个值。
- sequence?reverse 将sequence 的现有顺序反转,即倒序排序
- sequence?size 返回sequence 的大小
- sequence?sort 将sequence 中的对象转化为字符串后顺序排序
- sequence?sort_by(value) 按sequence 中对象的属性value 进行排序
注意:Sequence 不能为null 。
Hash 内置函数
- hash?keys 返回hash 里的所有key, 返回结果为sequence
- hash?values 返回hash 里的所有value, 返回结果为sequence
字符串函数
- substring (start,end )从一个字符串中截取子串。${"str"?substring(0,3)}结果为str
- cap_first 将字符串中的第一个单词的首字母变为大写。${"str"?cap_first}结果为Str
- uncap_first 将字符串中的第一个单词的首字母变为小写。${"str"?cap_first}结果为str
- capitalize 将字符串中的所有单词的首字母变为大写。${"str"?capitalize}结果为STR
- date、time、datetime 将字符串转换为日期。<#assign date1="2023-04-05"?date("yyyy-MM-dd")>${date1} 结果为2023-04-05
- ends_with 判断某个字符串是否由某个子串结尾,返回布尔值。${"string"?ends_with("ing")?string} 返回结果为true
- html 用于将字符串中的< 、> 、& 和“替换为对应得<>":&。。
- index_of (substring,start )在字符串中查找某个子串,返回找到子串的第一个字符的索引,如果没有找到子串,则返回-1 。${"string"?index_of("in")}结果为3
- length 返回字符串的长度。 ${"string"?length} 结果为6
- lower_case 将字符串转为小写。${"STRING"?lower_case}结果为string
- upper_case 将字符串转为大写。${"string"?upper_case}结果为STRING
- contains 判断字符中是否包含某个子串。返回布尔值。${"string"?contains('ing")?string}结果为true
- number 将字符串转换为数字。${88.99"?number}结果为88.99
- replace 用于将字符串中的一部分从左到右替换为另外的字符串。${"strabg"?replace("ab","in")} 结果为string
- split 使用指定的分隔符将一个字符串拆分为一组字符串。
- trim 删除字符串首尾空格。 ${" String "?trim} 结果为String
操作数字
- c 用于将数字转换为字符串。${438?c}结果为438
- string 用于将数字转换为字符串。<#assign num=99> ${num?string.number}结果为99
操作布尔值
string 用于将布尔值转换为字符串输出。 true 转为"true" ,false 转换为"false"。 wfsb?string("yes", "no") 如果布尔值是true, 那么返回"yes", 否则返回"no"。