原文地址
http://velocity.apache.org/engine/releases/velocity-1.6.4/developer-guide.html
How Velocity Works
1.Initialize Velocity. This applies to both usage patterns for Velocity, the Singleton as well as the 'separate runtime instance', and you only do this once.
2.Create a Context object.
3.Add your data objects to the Context.
4.Choose a template.
5.'Merge' the template and your data to produce the ouput.
To Singleton Or Not To Singleton
Singleton Model org.apache.velocity.app.Velocity
Separate Instance org.apache.velocity.app.VelocityEngine
不要改动org.apache.velocity.runtime
可以改动org.apache.velocity.app
The Context
数据容器。从java到模板的数据传输。
也算是一个API。
public Object put(String key, Object value);
public Object get(String key);
注意,like a Hashtable, the value must be derived from java.lang.Object, and must not be null.
Support for Iterative Objects for #foreach()
Object [],velocity自动把它包装成一个Iterator,并且,在1.6之后,可以直接在它之上调用List的方法。
java.util.Collection
java.util.Map
java.util.Iterator USE WITH CAUTION: This is currently supported only provisionally - the issue of concern is the 'non-resettablity' of the Iterator. If a 'naked' Iterator is placed into the context, and used in more than one #foreach(), subsequent #foreach() blocks after the first will fail, as the Iterator doesn't reset.
java.util.Enumeration USE WITH CAUTION: Like java.util.Iterator
Any public class with a public Iterator iterator() method that never returns null.
尽量不要把Iterator直接放入context,不可避免时要小心(大数据)。
Support for "Static Classes"
Context Chaining
Note:The changes to the context via #set() statements in a template will affect only the outermost context. 如果要在rendering后使用,注意不要扔掉outer context.
Objects Created in the Template
•The VTL RangeOperator [ 1..10 ] and ObjectArray ["a","b"] are java.util.ArrayList objects when placed in the context or passed to methods. Therefore, your methods that are designed to accept arrays created in the template should be written with this in mind.
•VTL Map references are unsurprisingly stored as java.util.Map.
•Decimal numbers will be Doubles or BigDecimals in the context, integer numbers will be Integer, Long, or BigIntegers, and strings will be, of course, Strings.
•Velocity will properly 'narrow' args to method calls, so calling setFoo( int i ) with an int placed into the context via #set() will work fine.
重要的问题
满足以下条件的情况下有可能内存泄露。
•You are iterating over the same template using the same VelocityContext object.
•Template caching is off.
•You request the Template from getTemplate() on each iteration.
其原因是VelocityContext (or any Context derived from AbstractContext) is node specific introspection caching.
解决办法
•Create a new VelocityContext for each excursion down through the template render process.
•Turn on template caching.
•Reuse the Template object for the duration of the loop iterations.
Using Velocity
可以调用Velocity的方法来实现Velocity的工作。
异常也设计的一看异常信息就知道错误在什么地方。
Application Attributes
Configuring Event Handlers
IncludeEventHandler
InvalidReferenceEventHandler
MethodExceptionEventHandler
NullSetEventHandler
ReferenceInsertionEventHandler
注册Handler,全局Handler,和一个Context建立关联。
Velocity Configuration Keys and Values
Configuring Logging
Configuring Resource Loaders
Template Encoding for Internationalization
Velocity and XML
转换xml文档。
分享到:
相关推荐
velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity用户手册velocity...
该文档为velocity学习笔记,包含一些常见问题
Velocity用户手册,主要讲解Velocity模板引擎的语法和使用
Velocity用户手册.doc
Velocity用户手册(中文版),Velocity语法的详细说明
Velocity用户手册_中文.docVelocity用户手册_中文.docVelocity用户手册_中文.doc
velocity学习笔记与struts2整合 velocity学习笔记与struts2整合 velocity学习笔记与struts2整合
Velocity用户手册---中文版.doc
velocity中文手册 Velocity 是一个基于java 的模板引擎(template engine)。它允许任何人仅仅简单的使 用模板语言(template language)来引用由java 代码定义的对象。
当Velocity应用于web开发时,界面设计人员可以和java程序开发人员同步开发一个遵循MVC架构的web站点,也就是说,页面设计人员可以只关注页面的显示效果,而由java程序开发人员关注业务逻辑编码。Velocity将java代码...
Velocity用户手册
当Velocity应用于web开发时,界面设计人员可以和java程序开发人员同步开发一个遵循MVC架构的web站点,也就是说,页面设计人员可以只关注页面的显示效果,而由java程序开发人员关注业务逻辑编码。Velocity将java...
velocity用户手册
Web设计者可以和Java程序开发者并行开发遵循MVC模式的Web站点。这意味着,Web设计者可以将精力放在好的Web站点设计上,而Java程序开发者可以将精力放在编写代码上。Velocity将Java代码从Web页面中分离,使Web站点更...
很不错,希望不喜欢e文的朋友观看,对于web的高阶进程,Velocity是不可或缺的一门技艺,兄弟们,Let‘s Go
关于velocity的学习资料,velocity教程和velocity用户手册
简单介绍了 velocity的用法,对日常开发过程中使用velocity技术的技术人员有一定参考价值
Velocity用户手册,绝对中文清晰版,一小时精通