- 浏览: 536535 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
飞天奔月:
public List<String> gener ...
实践中的重构30_不做油漆匠 -
在世界的中心呼喚愛:
在世界的中心呼喚愛 写道public class A {
...
深入理解ReferenceQueue GC finalize Reference -
在世界的中心呼喚愛:
在世界的中心呼喚愛 写道在世界的中心呼喚愛 写道在classB ...
深入理解ReferenceQueue GC finalize Reference -
在世界的中心呼喚愛:
在世界的中心呼喚愛 写道在classB的finalize上打断 ...
深入理解ReferenceQueue GC finalize Reference -
在世界的中心呼喚愛:
iteye比较少上,如果可以的话,可以发e-mail交流:ch ...
深入理解ReferenceQueue GC finalize Reference
Velocity的学习笔记
原文地址
http://velocity.apache.org/engine/releases/velocity-1.6.4/user-guide.html
简要
References begin with $ and are used to get something.
Directives begin with # and are used to do something.
注释 单行 ## 多行 #* *# doc #** *#
引用
变量
属性
注意$customer.Address可以表示customer的getAddress方法,也可以表示customer map中的Address对应的value.
方法
As of Velocity 1.6, all array references are now "magically" treated as if they are fixed-length lists. This means that you can call java.util.List methods on array references.
可变参数当作数组。
属性查找顺序
小写的属性$customer.address
1.getaddress()
2.getAddress()
3.get("address")
4.isAddress()
大写的属性$customer.Address
1.getAddress()
2.getaddress()
3.get("Address")
4.isAddress()
Rendering
引擎把每一个引用都转变为String,可以调用toString方法转变。
Formal Reference Notation
Jack is a ${vice}maniac.
Now Velocity knows that $vice, not $vicemaniac, is the reference. Formal notation is often useful when references are directly adjacent to text in a template.
Quiet Reference Notation
当$email没有定义的时候输出"".
Strict References Setting
对未定义变量,或null变量调用方法抛异常。
但是if语句可以使用未定义变量。
Directives
#set
For the ArrayList example the elements defined with the [..] operator are accessible using the methods defined in the ArrayList class. So, for example, you could access the first element above using $monkey.Say.get(0).
Similarly, for the Map example, the elements defined within the { } operator are accessible using the methods defined in the Map class. So, for example, you could access the first element above using $monkey.Map.get("banana") to return a String 'good', or even $monkey.Map.banana to return the same value.
这个比较容易迷惑人。
If the RHS is a property or method reference that evaluates to null, it will not be assigned to the LHS.
If $query.criteria("name") returns the string "bill", and $query.criteria("address") returns null, the above VTL will render as the following:
In the above example, it would not be wise to rely on the evaluation of $result to determine if a query was successful. After $result has been #set (added to the context), it cannot be set back to null (removed from the context).
One solution to this would be to pre-set $result to false. Then if the $query.criteria() call fails, you can check.
Literals
''和""的区别 ""可以"hello $name".
Alternately, the #literal script element allows the template designer to easily use large chunks of uninterpreted content in VTL code. This can be especially useful in place of escaping multiple directives.
Conditionals
If / ElseIf / Else
if测试(1)布尔值(2)引用是否为空
Relational and Logical Operators
Note that the semantics of == are slightly different than Java where == can only be used to test object equality. In Velocity the equivalent operator can be used to directly compare numbers, strings, or objects. When the objects are of different classes, the string representations are obtained by calling toString() for each object and then compared.
Foreach Loop
可以得到$velocityCount,$velocityHasNext。
变量名,起始下标都可以在配置文件里面更改。
还可以设置directive.foreach.maxloops。
在foreach中可以#break。
Include
The #include script element allows the template designer to import a local file, which is then inserted into the location where the #include directive is defined. The contents of the file are not rendered through the template engine. For security reasons, the file to be included may only be under TEMPLATE_ROOT.
Parse
The #parse script element allows the template designer to import a local file that contains VTL. Velocity will parse the VTL and render the template specified.
可以设置directive.parse.max.depth,默认是10.
允许递归。
Stop
The #stop script element prevents any further text or references in the page from being rendered. This is useful for debugging purposes.
Evaluate
The #evaluate directive can be used to dynamically evaluate VTL.
Define
The #define directive lets one assign a block of VTL to a reference.
Velocimacros
宏的参数和调用时的个数必须匹配。
宏有inline的宏,对其他模板不可见。
宏传递的是名字,注意宏执行的时间。
Velocimacro Properties
velocimacro.library
velocimacro.permissions.allow.inline
velocimacro.permissions.allow.inline.to.replace.global
velocimacro.permissions.allow.inline.local.scope
velocimacro.context.localscope
velocimacro.library.autoreload
Getting literal
有效velocity变量的转义
转义字符\
注意velocity对未定义变量和已定义变量的处理是不一样的。
无效velocity变量的转义
${my:invalid:non:reference}
改成
#set( $D = '$' )
${D}{my:invalid:non:reference}
Escaping VTL Directives
这个转义时要比较小心。
Other Features and Miscellany
Math 加减乘除 mod
Range Operator 设置数组和foreach.
Advanced Issues: Escaping and !
Can I use a directive or another VM as an argument to a VM?
No. A directive isn't a valid argument to a directive, and for most practical purposes, a VM is a directive.
但是可以#center( "#bold( 'hello' )" )
Can I register Velocimacros via #parse() ?
Yes! This became possible in Velocity 1.6.
This is important to remember if you try to #parse() a template containing inline #macro() directives. Because the #parse() happens at runtime, and the parser decides if a VM-looking element in the template is a VM at parsetime, #parse()-ing a set of VM declarations won't work as expected. To get around this, simply use the velocimacro.library facility to have Velocity load your VMs at startup.
对于宏定义的查找是在parsetime,所以runtime的parse中如果有宏会有问题。
What is Velocimacro Autoreloading?
宏自动加载,用于开发环境。
字符串连接
放在一起就好。
原文地址
http://velocity.apache.org/engine/releases/velocity-1.6.4/user-guide.html
简要
References begin with $ and are used to get something.
Directives begin with # and are used to do something.
注释 单行 ## 多行 #* *# doc #** *#
引用
变量
属性
注意$customer.Address可以表示customer的getAddress方法,也可以表示customer map中的Address对应的value.
方法
As of Velocity 1.6, all array references are now "magically" treated as if they are fixed-length lists. This means that you can call java.util.List methods on array references.
可变参数当作数组。
属性查找顺序
小写的属性$customer.address
1.getaddress()
2.getAddress()
3.get("address")
4.isAddress()
大写的属性$customer.Address
1.getAddress()
2.getaddress()
3.get("Address")
4.isAddress()
Rendering
引擎把每一个引用都转变为String,可以调用toString方法转变。
Formal Reference Notation
Jack is a ${vice}maniac.
Now Velocity knows that $vice, not $vicemaniac, is the reference. Formal notation is often useful when references are directly adjacent to text in a template.
Quiet Reference Notation
<input type="text" name="email" value="$email"/>当$email没有定义的时候输出$email.
<input type="text" name="email" value="$!email"/>
当$email没有定义的时候输出"".
Strict References Setting
对未定义变量,或null变量调用方法抛异常。
但是if语句可以使用未定义变量。
Directives
#set
#set( $monkey.Say = ["Not", $my, "fault"] ) ## ArrayList #set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map
For the ArrayList example the elements defined with the [..] operator are accessible using the methods defined in the ArrayList class. So, for example, you could access the first element above using $monkey.Say.get(0).
Similarly, for the Map example, the elements defined within the { } operator are accessible using the methods defined in the Map class. So, for example, you could access the first element above using $monkey.Map.get("banana") to return a String 'good', or even $monkey.Map.banana to return the same value.
这个比较容易迷惑人。
If the RHS is a property or method reference that evaluates to null, it will not be assigned to the LHS.
#set( $result = $query.criteria("name") ) The result of the first query is $result #set( $result = $query.criteria("address") ) The result of the second query is $result
If $query.criteria("name") returns the string "bill", and $query.criteria("address") returns null, the above VTL will render as the following:
The result of the first query is bill The result of the second query is bill
#set( $criteria = ["name", "address"] ) #foreach( $criterion in $criteria ) #set( $result = $query.criteria($criterion) ) #if( $result ) Query was successful #end #end
In the above example, it would not be wise to rely on the evaluation of $result to determine if a query was successful. After $result has been #set (added to the context), it cannot be set back to null (removed from the context).
One solution to this would be to pre-set $result to false. Then if the $query.criteria() call fails, you can check.
#set( $criteria = ["name", "address"] ) #foreach( $criterion in $criteria ) #set( $result = false ) #set( $result = $query.criteria($criterion) ) #if( $result ) Query was successful #end #end
Literals
''和""的区别 ""可以"hello $name".
#literal() #end
Alternately, the #literal script element allows the template designer to easily use large chunks of uninterpreted content in VTL code. This can be especially useful in place of escaping multiple directives.
Conditionals
If / ElseIf / Else
if测试(1)布尔值(2)引用是否为空
Relational and Logical Operators
Note that the semantics of == are slightly different than Java where == can only be used to test object equality. In Velocity the equivalent operator can be used to directly compare numbers, strings, or objects. When the objects are of different classes, the string representations are obtained by calling toString() for each object and then compared.
Foreach Loop
可以得到$velocityCount,$velocityHasNext。
变量名,起始下标都可以在配置文件里面更改。
还可以设置directive.foreach.maxloops。
在foreach中可以#break。
Include
The #include script element allows the template designer to import a local file, which is then inserted into the location where the #include directive is defined. The contents of the file are not rendered through the template engine. For security reasons, the file to be included may only be under TEMPLATE_ROOT.
Parse
The #parse script element allows the template designer to import a local file that contains VTL. Velocity will parse the VTL and render the template specified.
可以设置directive.parse.max.depth,默认是10.
允许递归。
Stop
The #stop script element prevents any further text or references in the page from being rendered. This is useful for debugging purposes.
Evaluate
The #evaluate directive can be used to dynamically evaluate VTL.
Define
The #define directive lets one assign a block of VTL to a reference.
Velocimacros
宏的参数和调用时的个数必须匹配。
宏有inline的宏,对其他模板不可见。
宏传递的是名字,注意宏执行的时间。
Velocimacro Properties
velocimacro.library
velocimacro.permissions.allow.inline
velocimacro.permissions.allow.inline.to.replace.global
velocimacro.permissions.allow.inline.local.scope
velocimacro.context.localscope
velocimacro.library.autoreload
Getting literal
有效velocity变量的转义
转义字符\
注意velocity对未定义变量和已定义变量的处理是不一样的。
无效velocity变量的转义
${my:invalid:non:reference}
改成
#set( $D = '$' )
${D}{my:invalid:non:reference}
Escaping VTL Directives
这个转义时要比较小心。
Other Features and Miscellany
Math 加减乘除 mod
Range Operator 设置数组和foreach.
Advanced Issues: Escaping and !
Can I use a directive or another VM as an argument to a VM?
No. A directive isn't a valid argument to a directive, and for most practical purposes, a VM is a directive.
但是可以#center( "#bold( 'hello' )" )
Can I register Velocimacros via #parse() ?
Yes! This became possible in Velocity 1.6.
This is important to remember if you try to #parse() a template containing inline #macro() directives. Because the #parse() happens at runtime, and the parser decides if a VM-looking element in the template is a VM at parsetime, #parse()-ing a set of VM declarations won't work as expected. To get around this, simply use the velocimacro.library facility to have Velocity load your VMs at startup.
对于宏定义的查找是在parsetime,所以runtime的parse中如果有宏会有问题。
What is Velocimacro Autoreloading?
宏自动加载,用于开发环境。
字符串连接
放在一起就好。
发表评论
-
http core 4.2.2 StringEntity 的一个疑问
2013-01-17 22:53 3718代码在org.apache.http.entity.Strin ... -
hamcrest core and lib 1.1阅读体会
2010-09-26 01:20 1529阅读完了hamcrest core and lib 1.1,h ... -
jmock2.5基本教程
2010-09-24 15:32 3347jmock2.5基本教程 目录 ... -
Tile2学习笔记
2010-08-02 22:53 1122Tile 一句话介绍:模板化技术,加速web程序的开发。 ... -
Spring 集成视图技术 学习笔记
2010-08-01 21:34 1046这是一个Spring集成视图技术的学习笔记 基本上是一个精简 ... -
SpringMVC学习笔记
2010-08-01 20:36 1467这是一个SpringMVC的学习笔记 基本上是一个精简版的S ... -
Velocity开发手册学习笔记
2010-07-18 15:21 1129原文地址 http://velocity.apache.org ... -
maven的依赖传递
2010-06-23 19:46 3199maven2提供了强大的依赖 ... -
Spring Web Security3.0 初体验
2010-01-21 10:13 1758看了看Spring Web Security3.0 ... -
Drools 5 Expert新特性
2009-06-20 08:11 3098Drools5的一些重要改动。 改一些基本类名字。Drool ... -
jbpm的task assignment和identity model
2009-06-17 12:57 1468在jbpm中,task可以指派给 ... -
jbpm的例子之六 使用swimlane
2009-06-17 12:24 1647使用swimlane可以让process的task的assig ... -
jbpm的例子之五 使用timer
2009-06-09 17:04 1136jbpm的版本为3.2.3 timer本身是由JobExec ... -
jbpm的例子之四 使用decision
2009-06-09 10:52 1175decision节点可以实现多路选择。 <?xml v ... -
jbpm的例子之三 使用fork
2009-06-08 18:56 1050fork的使用有一些小的地方需要注意。 1 fork节点出去 ... -
jbpm的教程的例子之二 两个task
2009-06-08 17:25 756当process流进task-node 't'的时候,进入wa ... -
jbpm的教程的例子之一 HelloWorld.
2009-06-08 16:15 1082重新改了一下jbpm的教程的第一个例子,希望对刚接触jbpm的 ... -
Geronimo中GBean的引用
2009-04-20 10:52 1326Geronimo中GBean的引用。 1 在GBean中定义 ...
相关推荐
阅读Velocity用户手册中文版,可以从基础语法开始学习,逐步掌握变量引用、条件控制、循环等基本操作。同时,了解如何将Velocity集成到你的项目中,以及如何调试和优化模板,是成为Velocity熟练使用者的关键步骤。 ...
通过阅读这份中文版的Velocity用户手册,你将能够掌握如何使用Velocity进行模板设计,理解其核心概念,并能熟练运用到你的Web开发项目中。不断实践和探索,你将发现Velocity是一个强大的工具,能帮助你轻松构建高效...
### Velocity学习笔记精要 **一、Velocity简介与特点** Velocity是一种基于Java的模板引擎,用于将静态数据和动态内容结合在一起,生成最终的HTML、XML或其他格式的文档。其最大的特点是性能高、易于理解和使用,...
Velocity 是一个基于 Java 的模板引擎,它允许开发者使用模板语言(Template Language)来引用由 Java 代码定义的对象。其核心理念是将Java代码与HTML页面内容分离,促进MVC(Model-View-Controller)架构的实现,...
Velocity 使用一种称为 Velocity Template Language (VTL) 的模板语言,这种语言允许模板中的文本与 Java 对象相互作用,以动态生成内容。 VTL 的基本元素包括变量、属性、方法、注释和指令。变量用于引用 Java ...
假设一个在线MUD商店,Velocity使得根据用户购买记录显示个性化商品推荐变得简单。设计人员可以在页面上嵌入Velocity模板语言(VTL),通过VTL引用Java对象来动态生成内容。 【Velocity Template Language (VTL)】 ...
Velocity 是一个基于 Java 的模板引擎,它主要用于将静态页面内容与动态数据相结合,实现模板语言与 Java 代码的分离。...通过学习和掌握 Velocity,开发者能够更高效地构建出响应用户需求、易于维护的 Web 应用程序。
- Velocity 用户需要准备特定的 JAR 包,以便在项目中使用 Velocity。 - Maven 用户可以通过 Maven 依赖的方式添加所需的 JAR 包。 - 其他用户则需要手动下载和添加 JAR 包到项目中。 8. 使用 Velocity 的注意...
在“Velocity用户手册”中,你将学习到如何使用Velocity来构建动态网页和应用程序。手册可能涵盖了以下内容: 1. **Velocity基础**:包括Velocity的基本概念,如模板语言、变量、指令和宏。Velocity的模板语言(VTL...
### Velocity用户手册精要 **一、Velocity简介与能力范畴** Velocity是一款强大的模板引擎,其功能远远超越了web站点开发的局限。它不仅能够用于创建动态网页,还具备生成SQL、PostScript、XML等各类文档的能力,...
**Velocity简介** Velocity是一款强大的Java模板引擎,由Apache软件基金会开发并维护,是Apache Jakarta项目的一部分。...如果你在Web开发中追求更好的用户体验和更高的开发效率,那么学习和掌握Velocity将是值得的。
velocity中文手册 Velocity 是一个基于java 的模板引擎(template engine)。它允许任何人仅仅简单的使 用模板语言(template language)来引用由java 代码定义的对象。
为了更好地使用Velocity,Velocity用户手册提供了详细的例子和说明。手册中包含了对VTL的详细介绍,比如变量的使用、控制结构的编写、指令的应用等,以帮助页面设计者和内容提供者快速熟悉和掌握Velocity的使用。...
通过学习和掌握Velocity用户手册,你可以提升你的Web开发技能,创造出更加用户友好、高度定制的Web体验。无论你是页面设计师还是Java开发者,Velocity都能帮助你更好地实现Web应用的MVC设计,并提高开发效率。