Java template engine FreeMarker Introduction

Source: Internet
Author: User

FreeMarker is a template engine. It is a common tool for generating text output based on templates and written in Java only. FreeMarker is designed to generate HTML Web pages (to speed up page access, static pages), especially MVC-based applications.

The FreeMarker operation process is as follows: Define the template file and prepare the data,

FreeMarker is not a Web application framework, but is suitable as a component of the Web application framework.

FreeMarker has nothing to do with containers because it does not know HTTP or Servlet. FreeMarker can also be applied to non-Web application environments.

FreeMarker is more suitable as a view component of the Model2 framework (such as Struts). You can also use the JSP tag library in the template.

FreeMarker is free of charge

You can also use the Eclipse plug-in to edit FreeMarker. After verification, the best Eclipse editing plug-in for FreeMarker is JBoss Tools.

FreeMarker features
1. General Purpose
Ability to generate various texts: HTML, XML, RTF, Java source code, etc.
Easy to embed into your product: lightweight; no Servlet environment required
Plug-in template Loader: you can load templates from any source, such as local files and databases.
You can generate text as needed: Save it to a local file; send it as Email; send it back to a Web browser from a Web application
2. Powerful template Language
All common commands: include, if/elseif/else, and loop structure
Create and change variables in the template
You can use a complex expression to specify a value almost anywhere.
Named macros that can have location parameters and nested content
Namespace helps you build and maintain reusable macro libraries, or split a large project into modules without worrying about name conflicts.
Output conversion block: HTML Escape, compression, and syntax highlighting are converted when embedded template fragments generate output. You can define your own conversion.
3. General Data Model
FreeMarker does not directly reflect to Java objects. Java objects are encapsulated by plug-in objects and displayed in the template as variables.
You can use abstract (Interface) Methods to represent objects (JavaBean, XML documents, SQL query result sets, and so on) and tell template developers how to use them so that they are not subject to technical details.
4. Prepare for the Web
Built-in structure for processing typical Web-related tasks (such as HTML escaping) in the template Language
Can be integrated into the Model2 Web application framework as a substitute for JSP
Support JSP tag Library
Design for MVC mode: Separate visual design and application logic; Separate page designers and programmers
5. Intelligent internationalization and Localization
Intelligent Character Set (UNICODE is used internally)
Digital format localization sensitive
Localized sensitive Date and Time formats
Non-US character sets can be used as Identifiers (such as variable names)
Same template in multiple languages
6. Powerful XML processing capabilities
<# Recurse> and <# visit> commands (Version 2.3) are used to recursively traverse the XML tree.
Clear and intuitive access to the XML Object Model in the template

 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.