Freemarker is a template engine, a generic tool that generates text output based on a template, written in plain Java
Freemarker is designed to generate HTML Web pages, especially for applications based on MVC patterns
Although Freemarker has some programming capabilities, it is common for Java programs to prepare the data to be displayed, generate pages from Freemarker, and display prepared data through templates (such as)
Freemarker is not a Web application framework and is suitable as a component of the Web application framework
Freemarker is not associated with a container because it does not know that HTTP or servlet;freemarker can also be applied to a non-web application environment
Freemarker is more suitable as a view component for MODEL2 frameworks such as struts, and you can also use JSP tag libraries in templates
Freemarker is free.
And you can edit the Freemarker through the Eclipse plugin, and it's proven that Freemarker's best eclipse editing plugin is JBoss Tools.
Freemarker characteristics
1. Universal Target
Ability to generate various types of text: HTML, XML, RTF, Java source code, etc.
Easy to embed into your product: lightweight; no servlet environment required
Plug-in Template loader: Templates can be loaded from any source, such as local files, databases, and so on
You can generate text as you want: save to a local file, send it as an email, send it back to the Web browser from the Web application
2. Powerful Template language
All common directives: include, if/elseif/else, loop structure
Create and change variables in a template
You can use complex expressions to specify values almost anywhere
Named macros, which can have positional parameters and nested content
namespaces help you build and maintain reusable macro libraries, or divide a large project into modules without worrying about name collisions
Output Transform block: Transforms HTML escape, compression, syntax highlighting, and so on when generating output from nested template fragments; You can define your own transformations.
3. General Data Model
Freemarker is not reflected directly to Java objects, Java objects are encapsulated by plug-in objects and are displayed in a template in a variable way
You can use abstract (interface) representations of objects (JavaBean, XML documents, SQL query result sets, and so on) to tell template developers how to use them so that they are not disturbed by technical details
4. Prepare for the web
Constructs built-in in the template language to handle typical web-related tasks such as HTML escaping
Can be integrated into the MODEL2 Web application framework as a substitute for JSP
Support for JSP tag libraries
Designing for MVC Patterns: Separating visual design and application logic; Separating page designers and programmers
5. Intelligent Internationalization and localization
Character Set intelligence (Unicode is used internally)
Digital format Localization Sensitive
Date and time format localization sensitive
Non-US character sets can be used as identifiers (such as variable names)
The same template in many different languages
6. Powerful XML processing capability
< #recurse > and < #visit > directives (version 2.3) for recursive traversal of XML trees
Clear and intuitive access to the XML object model in templates
Open Source Forum Jforum is the use of Freemarker as a page template.
Java Template engine Freemarker