1 Overview
l Velocity is a simple and more lightweight tool, but it does not meet many of the tasks that freemarker can do, and its template language is not very powerful.
l We think that for most applications, FreeMarker is more simple than Velocity, because:
Ø Use Velocity, you need to find a specific tool or a variety of working environment to solve typical template creation tasks at a time, and the result is wasting more time
Ø The working environment often means that the Java objects are used directly in the Velocity template, which violates the concept of simple, no programming HTML design.
Ø Or transferred to the controller code, which violates the MVC mode
l Using FreeMarker, you can achieve Velocity can do with out-of-a-box (how to translate it exact?)
2, characteristic comparison list
Below is an uncommon feature list that uses FreeMarker to be implemented, and Velocity cannot achieve a list of notified features:
(1) Digital and date support
l Mominable comparisons and comparisons can be performed on any digital type, including accuracy types.
l You can compare and display (format) date / time value
(2) Internationalization
l Format local sensitive numbers based on a variety of built-in and custom digital formats
l Format local sensitive and time zone sensitive dates based on various built-in and custom date formats
l Identification (variable name) can include non-English characters, such as stress characters, Arabic characters, Chinese characters, etc.
(3) cycle processing
l You can jump out of the loop
l Access control variables within the cycle outside the cycle
l You can test whether to reach the last cycle
(4) Array processing of template level
l You can use an indexing mode similar to [i] syntax to access array elements
l You can query the array length
(5) macro
l Macro can have local variables
l You can recursively call the macro, and you can also define the macro to be called later on the template.
l When calling a macro, you can transfer parameters in a location or name.
l Macro parameters can have a default value so that the parameters are ignored when calling.
l The macro called can have nested body content (<@mymacro> Body @ mymacro>), which can be processed when the macro is called
l Macro is pure variable, can perform macros based on the expression, or transmit it to another as a parameter.
(6) Namespace
l You can use multiple namespaces for variables, which is important for creating a macro library because this avoids the variables specified in the application and the name conflict of variables in the macro library.
(7) Use built-in functions / operator Maintaining Java-independent String, List, and Map
l Convert the string to large / lowercase, first character large / lowercase, transfers for HTML, XML or RTF, Substring, Split, Query string length, Find / Replace substring, etc.
l Access the List element by index, obtain sub-List, merge LIST, query the List length, sort LIST
l Access the MAP element via the key variable, check if the MAP is empty, get the list of the key or value.
(8) Revealing the error in the template when accessing an undefined variable, FreeMarker will not be silent; you can configure freemarker to stop the Render template to display the error message, or skip the wrong part; no matter, FreeMarker will record the problem (log )
l When you write the wrong command name, FreeMarker will throw an exception.
(9) Advanced Render Control
l You can use a set of tags to encapsulate a piece of area of the template to apply HTML or XML escape (or other converted by the FreeMarker expression) in the block area to be modified.
l FreeMarker has a converter, which is a zone of the template. When render, by converting filtering; the built-in converter includes blank character compression, HTML, and XML escape; you can implement your own converter; of course the converter can be embedded set
l You can use the Flush command explicit FLUSH output
l You can use the STOP instruction to stop Render
(10) text
l In addition to the usual strings, numbers, and Boolean text, you can also define List and Map text in the template.
l Support all Java escape text: / b, / t, / n, / f, / r, / ", / ', //, also support / xxxxx using unicode specified characters
(11) Advanced blank character removal
l FreeMarker insists on removing a blank character that only contains free femarker tags.
l For instructions that obviously try to complete the blank character, blank characters is a big problem.
(12) Integrated other technologies
l You can use the JSP tag library in the template
l can be used directly in Python projects
(13) Powerful XML conversion capability
l In version 2.3, FreeMarker has powerful new XML conversion capability, making it possible to replace XSLT
l Velocity is unable to actually compete in this regard unless the core engine is improved, such as supporting the macro library to map to the namespace, the macro supports local variables.
(14) Advanced Template Program
l You can capture any part of the output to the context variable.
l You can explain any context variable if it is a template definition.
l Use of the above two