Freemarker是当今最为优秀的模板引擎之一。提供了丰富的功能以及优秀的运行性能。Beetl是新一代的模板语言,提供了比feemarker更多的实用功能以及更好的运行性能,他们的比较如下
功能对比
完全参考了Freemarker官方文档(2.3.19) 第一列是官方文档目录,第二列是表示beetl中是否具有同样的功能
通过下列表格,可以看出绝大部分功能,beetl都是支持的。
功能
|
是否支持
|
备注
|
1.1 简介
|
支持
|
|
1.2模板 + 数据模型 = 输出
|
支持
|
|
1.3 数据模型一览
|
支持
|
|
1.4.1 简介
|
支持
|
|
1.4.2 (.1--.4) 指令示例
|
支持
|
Beetl中,采用includeFileTemplate标签来include一个文件。Beetl中还支持switch/case
|
1.4.2.5 处理不存在的变量
|
支持
|
不支持询问变量是否存在,但可以通过扩展函数来支持
|
2.1 基本内容
|
支持
|
|
2.2.1 类型 简介
|
大部分支持
|
很少使用的节点类型不支持
|
2.2.2 标量
|
支持
|
|
2.2.3 容器
|
支持
|
|
2.2.4 方法和函数
|
支持
|
可以通过扩展函数来间接支持
|
2.2.5 其它(节点类型)
|
不支持
|
|
3.1 总体结构
|
支持
|
|
3.2 指令
|
支持
|
|
3.3 表达式
|
支持
|
集合操作不支持,但可以通过扩展函数来实现集合操作。
截取字符串也不是内置的,但可以通过扩展函数来实现,如str.subString
|
3.3.3.1 字符串
|
支持
|
|
3.3.3.2 数字
|
支持
|
|
3.3.3.3 布尔值
|
支持
|
|
3.3.3.4 序列
|
支持
|
采用js语法的json格式支持。但不包括支持start..end 这样的方式
|
3.3.3.5 哈希表
|
支持
|
|
3.3.4 检索变量
|
支持
|
|
3.3.5 字符串操作
|
不支持
|
此语法很奇怪,只能说freemaker复杂了语法
|
3.3.5.2 获取一个字符
|
支持
|
通过扩展函数支持
|
3.3.6.1 序列操作 连接
|
支持
|
通过扩展函数支持
|
3.3.6.2 序列切分
|
支持
|
通过扩展函数支持
|
3.3.7 哈希表操作 连接
|
支持
|
|
3.3.8 算数运算
|
支持
|
|
3.3.9 比较运算
|
支持
|
|
3.3.10 逻辑操作
|
支持
|
|
3.3.11 内建函数
|
支持
|
|
3.3.13 处理不存在的值
|
支持
|
通过扩展函数支持
|
3.3.13.1 默认值
|
部分支持
|
|
3.3.13.2 检测不存在的值
|
支持
|
|
3.3.14 括号
|
支持
|
|
3.3.15 表达式中的空格
|
支持
|
|
3.3.16 操作符的优先级
|
支持
|
无数字范围 这个概念
|
3.4 插值
|
支持
|
|
4.1 自定义指令 (宏)
|
支持
|
间接通过标签等支持
|
4.1.4 嵌套内容
|
支持
|
Beetl中主要用在layout标签里
|
4.1.5 宏和循环变量
|
支持
|
|
4.2 在模板中定义变量
|
支持
|
|
4.3 命名空间
|
部分支持
|
通过扩展函数支持,
|
4.4 空白处理
|
支持
|
Beetl中不需要此额外功能
|
4.5替换(方括号)语法
|
支持
|
|
性能比较
单线程:
还是以常用模板为准(大小6K),循环渲染50000次,需要时间(毫秒为单位)如下
Beetl1.2M1 解释执行方式(普通模式),运行三次,分别 1356,1365,1348
Beetl1.2M1 编译执行方式(普通模式),运行三次,分别 913,922,905
Freemarker 分别是 1155,1130,1122
Beetl1.2M1 允许字节流优化,解释方式执行三次,分别是 587,605,610
Beetl1.2M1 允许字节流优化,编译方式执行三次,分别是 385,355,370
简而言之,对beetl做运行时编译,byte输出设定后,渲染5万次6K的模板,性能如下
Freemarker
|
Beetl
|
1140毫秒
|
370毫秒
|
及时不对beetl做任何优化,性能也与Freemarker持平
Freemarker,Velocity,Beetl 功能比较:
http://freemarker.sourceforge.net/fmVsVel.html 是一篇freemaker与velocity功能比较的文章,我在此基础上,增加了Beetl功能,可以看出,Beetl支持的功能还是超过了Freemarker。
如下表所示
功能点
|
Beetl
|
Freemarker
|
velocity
|
自定义控制语句
|
yes
|
no
|
no
|
自定义占位符号
|
yes
|
no
|
no
|
严格MVC控制
|
yes
|
no
|
no
|
虚拟属性
|
yes
|
no
|
no
|
文本处理函数
|
yes
|
yes
|
no
|
自定以错误处理Hanlder
|
yes
|
no
|
no
|
安全输出
|
yes
|
no
|
no
|
运行中编译class
|
yes
|
no
|
no
|
变量作用域
|
yes
|
no
|
no
|
Number and date support
|
yes
|
yes
|
no
|
Internationalization:
|
Yes,但不支持中文变量名
|
yes
|
no
|
Loop handling:
|
Yes
|
yes
|
no
|
Array handling on the template language level
|
yes
|
yes
|
no
|
Macros
|
Yes
,间接支持 |
Yes
|
no
|
Name-spaces:
|
No
|
yes
|
no
|
Java-independent string, list, and map manipulations with built-in functions/operators:
|
yes
|
yes
|
no
|
Expose typos and other mistakes in template
|
Yes |
yes
|
no
|
Advanced rendering control:
|
yes
|
yes
|
no
|
Literals:
|
yes
|
yes
|
no
|
Advanced white-space removal
|
No,beetl不需要此额外功能
|
yes
|
no
|
Integration with other technologies:
|
yes
|
yes
|
yes
|
Powerful XML transformation capabilities:
|
no
|
yes
|
no
|
Advanced template metaprogramming:
|
no
|
yes
|
no
|
function
|
no
|
yes
|
No
|
Beetl栏总共有19个yes,freemarker有16个yes,velocity只有1个