这是最近几个月beetl
使用者完成的俩个电商网站截图:
最近在做中文翻译成英文以走出国门,没有翻译完,还有30多页了,虽然翻译的蹩脚,但看着已经有点像模像样了,等着慢慢优化,如果有自愿者能帮助,那就更好了
Beetl Guid
---Joel Li
2012-6-29
1.
What is Beetl
............................................................................................................
2
1.1.
What beetl can do for you
..........................................................................
3
2.
Basic
Usage.........................................................................................................
3
2.1.
Hello Beetl
..................................................................................................
3
2.2.
Delimiter
of Placeholder and Statment..........................................................
4
2.3.
Define variable.............................................................................................
5
2.4.
算术表达式
.................................................................................................
7
2.5.
逻辑表达式
.................................................................................................
7
2.6.
循环语句
.....................................................................................................
7
2.7.
条件语句
.....................................................................................................
9
2.8.
函数调用
...................................................................................................
10
2.9.
格式化
......................................................................................................
10
2.10.
直接调用
class方法和属性
..........................................................................
11
2.11.
错误处理
...................................................................................................
11
2.12.
安全输出
...................................................................................................
12
2.13.
注释
..........................................................................................................
12
2.14.
其他琐碎功能
............................................................................................
13
3.
高级用法
.................................................................................................................
15
3.1.
总是使用
GroupTemplate............................................................................
15
3.2.
允许优化,超越其他模板引擎
...................................................................
16
3.3.
允许
Byte直接输出
....................................................................................
17
3.4.
自定义函数
...............................................................................................
18
3.5.
格式化函数
...............................................................................................
19
3.6.
严格
MVC控制
..........................................................................................
20
3.7.
虚拟属性
...................................................................................................
21
3.8.
标签
..........................................................................................................
21
3.9.
宏
.............................................................................................................
22
3.10.
空格处理
...................................................................................................
23
3.11.
自定义错误处理
........................................................................................
24
4.
Spring MVC.............................................................................................................
24
4.1.
配置
ViewResolver......................................................................................
24
4.2.
模板中获取参数
........................................................................................
25
5.
在
Servlet中使用
Beetl.............................................................................................
26
5.1.
配置
Linstener............................................................................................
26
5.2.
编写
Servlet...............................................................................................
28
6.
附录:扩展包
..........................................................................................................
28
6.1.
函数
..........................................................................................................
29
6.2.
格式化函数
...............................................................................................
29
6.3.
标签
..........................................................................................................
29
6.4.
Freemarker功能对比
..................................................................................
30
6.5.
Freemarker性能比较
..................................................................................
33
6.5.1.
单线程:
............................................................................................
33
6.5.2.
并发
...................................................................................................
34
Beet
l
is abbreviation of Bee template language
,current version is 1.2M1
,total size 360K (include antlr runtime lib)
,
the features of beetl
as following:
1
very simple
:It is a JavaScript-like grammar with a few symbol
。Anyone who familiar with java or javascript can master very soon.
2
Full functionality
:
It
is fully functional template language, support lots of features which current
popular Template engine support ,such as FreeMarder
(ref 附录freemarker
功能对比
)
3
extremely high performance
:If enable compiling template to java class and enable direct byte outputting
,the speed of rendering template is fastest in popular template
engines
,the consume of system resource is lower than
other template engine
(ref 附录freemarker
功能对比
)
4
unique features
,self customized placeholder
,virtual
attribute for model
,,self customized function, formatter,
Tag and safe outputing etc
。these features are easy
understand and can solve many template rendering issue
5
Support both MVC and strict MVC
, you can
forbid
evaluate expression
and complicated logic expression if you think
these should be put in logic layer not view layer
,please
refer strictly enforces model-view separation
6 can be easily
integrated with other Web Framework, such as Spring, Servlet .etc.
in 1 minute
As
template language, you can make use of it in any place of
MVC
base on Java
,such as Web page
,Code generation. You also can learn Antlr if you are interesting in it
because Beetl is a template language based on
Antlr
package
org.bee.tl.samples;
import
org.bee.tl.core.GroupTemplate;
import
org.bee.tl.core.Template;
public
class
Helloworld
{
public
static
void
main(String[] args)
throws
Exception
{
String
input =
"hello,${name}!"
;
GroupTemplate
group =
new
GroupTemplate();/1
Template
template = group.getStringTemplate(input); /2
template.set(
"name"
,
"beetl"
);/3
String
output = template.getTextAsString();/4
System.
out
.println(output);
}
}
|
1
Create GroupTemplate with empty constructor
so it can make a String Template
。
In
most case
,template is
file, so you can create GroupTemplate with the file root of templates, for
example: GroupTemplate
group = new
GroupTemplate(“c:\templateroot”)
2 In
this case , the template is a string "hello,${name}!"
,so,
you can call method getStringTemplate to get Template instance.
“${
” “}
” are
placeholder in template
。The expression in placeholder is
evaluated and output to the StringWriter
If
template is a file, you must call method getFileTemplate
,pass
a relative path to root as the
parameter. For examples:
GroupTemplate
group = new GroupTemplate(“c:/templateroot”)
/* c:/templateroot/user/userList.html is template file */
Template template
=
group.getFileTemplate(“/user/userList.html”);.
3
template.set(
String key
,
Object value
) just define Template variable which can be
referenced in any place of
Template
,the
parameter String is variable name followed Java(Javascript) name convention
,the parameter Object is value of variable which can be any java Object
instance.
You can reference object
attribute by using “.” For example
${user.name},If
Objec is array or subclass of java.util.List or
,you
can refrence item using index,such as ${user.friends[0]},if Object is subclass
of Java.util.Map
,
you
can refrence the value by key,for example ${books[
‘thinking in java
’].author}
4 you can get the
output by call
template.getTextAsString()
or template.getText(Writer) or
template.getText(OutputStream os)
( NOTE
:only
OutputStream can be used if you
using advance features
direct byte
output
)。In
this example
,the output is hello,beetl!
By default
, “<%”
is the start delimiter of Statement
,%> is the end
delimiter of statement
<%
for(user in userList){ %>
hello,${user.name}
<%}%>
|
By default,
the Beetl expression between
"${"
and "}" will be evaluated and output.
Beetl can define
delimiter of placeholder and statement as your favorite. For example you can
define <!--:
--> as your delimiter
of statement in HTML template.
public static void main(String[] args) {
GroupTempate group = new GroupTemplate(root);
group.setStatementStart("<!--:");
group.setStatementEnd("-->");
group.setPlaceholderStart("${");
group.setPlaceholderStart("}");
//
or call
config method for simplify
//group.config("<!--","-->","${","}");
File child = …..
Template template =group.getFileTemplate(child);
String output = template.getTextAsString();
}
|
In this case,
Beetl can parser the following template
<!--:
var name=
”lijz
”;
var
greeting =
“morning
”;
-->
<p>Hello
${name} ${greeting~}</p>
|
Note: the default delimiter of statement are “<%”
“%>” ,the default delimiter of placeholder are “${“
“ }”
Beetl have
two kinds of variable.one is global variable which can be referred in any place(
include child template)
,the global variable is readonly and set value
by call template.set(String,Object) in Java code
,Another
variable is
temporary variable which only
defined in Template
such as
<%var
name='lijz',loopCount=100+other ,girlName;%>
|
(The
keyword “var” is necessary
, it’s differ
from
javascript) .
There is no
scope for temporary variable( like java)
,the ,the following
code will get error of
“variable has
defined “name”
。
<%var
name=
’lijz
’,i=1; %>
<%if(i>=1){%>
<%var name='lucy';%>
Hello,${name}
<%}%>
|
Beetl also support JSON variable like javascript.
It’s intuitive but I recommend model is defined in business layer not view
layer
<% var
usersList=[{
“name
”:
”lijz
”,
”age
”:18},{
“name
”:
”lucy
”,
”age
”:16}];%>
She’s ${userList[1][
“name
”]}
|
As above template fragment ,there is two item
in array “usersList”
, each item include a Map
,so the value of key “name” is “lucy” for the second item .
Beetl always
wrap number object (int,float,double,Bigdecimal) as BeeNumber to support large
scale calculation, so don’t worry the high precision computation .I recomand DO
not do calculation if this is a part of business logic since we must try to
flow MVC principle.
NOTE
The variable
name is followed Java(JavaScript) name convention, but can not define the variable
name start with “__” since it’s for internal using.
- 大小: 85.7 KB
- 大小: 37.1 KB
分享到:
相关推荐
毕业设计javassm珠江学院大学生自愿者服务网+vue源码含文档含教程 后台是ssm框架,后台的页面是vue,前端页面是html,数据库mysql,jdk1.8,开发工具用ecplise、myecplise、sts、idea都可以 珠江学院大学生自愿者...
IEEE829测试文档标准是软件测试领域的一个重要文档规范,它详细描述了一套基础软件测试文档的格式和内容。这个标准由IEEE计算机协会软件工程技术委员会赞助,并在1998年9月16日获得了IEEE-SA标准委员会的批准。IEEE...
自愿者培训心得.doc
文档强调了遵守H.264标准是自愿的,但在某些情况下,可能包含强制性条款以保证互操作性和适用性。 此外,文档中还提出了关于知识产权的问题,指出使用H.264标准可能会涉及已申报的知识产权,而国际电信联盟(ITU)...
珠江学院大学生自愿者服务网+vue
【标题】"基于ssm+vue珠江学院大学生自愿者服务网"是一个综合性的项目,它融合了多种技术,旨在为珠江学院的大学生提供一个志愿服务平台。这个项目利用了Java的SSM(Spring、SpringMVC、MyBatis)框架与前端的Vue.js...
且社会责任报告的质量与市场的表现有一定的正相关性.研究表明社会责任报告整体质量偏低、公众的企业社会责任意识较弱是制约资本市场对企业社会责任信息披露评价的主要因素.本文的研究发现为企业与监管政策从一味追求...
基于java的学院大学生自愿者服务网站设计与实现
文档中使用“应当”或“必须”这样的词汇,并不改变其作为自愿标准的地位,也不削弱免责声明。这意味着设备供应商虽然可以选择是否将标准元素纳入其产品,但如果他们声称产品符合此标准,那么就等于承诺其产品包含或...
数据库课程设计ssm706珠江学院大学生自愿者服务网+vue.sql
珠江学院大学生自愿者服务网站 SSM毕业设计 附带论文 启动教程:https://www.bilibili.com/video/BV1GK1iYyE2B
12. 使用母语/目标语言:老师会要求学生将某些内容翻译成母语或目标语言,“Put it/them into Chinese/English.”(请把它们翻译成中文/英文。) 13. 物品要求:老师会要求学生拿出或使用特定物品,如“Please open...
4. **标准化进程**:修正案强调了IEEE标准文档的开发是在IEEE社会和IEEE-SA标准委员会的协调下进行的,参与标准制定的成员是自愿服务且无薪酬的专家。这些标准代表了IEEE内部广泛的专业知识以及外部参与者的意见和...
本项目为“珠江学院大学生自愿者服务网”,专为计算机相关专业学生及Java学习者设计,提供毕业设计、课程设计的高分资源。项目源码、数据库脚本及开发说明等一应俱全,并附论文参考,可直接用于毕设。 项目采用...
贡献 组织gh页部署了master分支,因此在该source分支上进行了积极的开发。 该网站是用site/中的JS和Markdown文件编写的。...发布网站推送到source分支后,Travis CI将发布贡献者感谢这些很棒的人():
收集整理的,请自愿下载,注意英文文档,公益事项请不要恶意传播
学院大学生自愿者服务网站 SSM毕业设计 源码+数据库+论文(JAVA+SpringBoot+Vue.JS) 启动教程:https://www.bilibili.com/video/BV1GK1iYyE2B
基于SSM+Vue的珠江学院大学生自愿者服务网毕业设计(源码+延时录像+说明).rar 【项目技术】 开发语言:Java 框架:ssm+vue 架构:B/S 数据库:mysql 【演示视频-编号:706】 https://pan.quark.cn/s/b3a97032fae7