FreeMarker software introduction
FreeMarker.jar, simply put, is a universal tool based on templates and data to be changed, and used to generate output text (HTML web pages, emails, configuration files, source code, etc.). Its emergence is mainly to solve the problem of the lack of freemarker.jar in Struts2. It is not designed for end users, but is a Java class library, a component that programmers can embed into the products they develop. In other words, this is just like a tool component, used in conjunction with other software. It is written in Java language and is mainly used for the view layer in MVC. It generates HTML to display data to the client and can completely replace JSP. The software is independent of the Web container, that is, it does not know servlets or HTTP when running on the Web. It can not only be used as an implementation technology for the presentation layer, but also generate the Java programming language, etc.
FreeMarker software features
Templates do not contain program logic to find out who the current visitors are, or to query the database for the latest products. The data displayed is prepared outside of FreeMarker, usually in some "real" programming language (such as Java ). The template author does not need to know how these values are calculated. In fact, the way these values are calculated can be completely modified while the template remains unchanged, and the style of the page can be completely modified without changing the template. Separating display logic from business logic is useful when the template author (designer) and programmer are not the same person. Even if the template author and programmer are the same person, doing so will help manage the complexity of the application. Make sure the template focuses on presentation issues (visual design , layout and formatting) are key to using template engines efficiently
How FreeMarker works
Suppose that an HTML page is required in an application system as follows:
The username in the page (i.e. "Big Joe" above) is the name of the visitor who logged in to this page. And the latest product data should come from the database so that it can be updated at any time. Therefore, you cannot directly enter "Big Joe", "greenmouse" and links into the HTML page. Static HTML code cannot be used. This can be solved by using a template that requires output. The template is the same as the static page, except that it will contain some instructions for FreeMarker to turn them into dynamic content:
The template file is stored on the Web server. When someone visits this page, FreeMarker will step in and execute it, then dynamically convert the template, replace the ${...} part of the template with the latest data content, and then send the result to the visitor's Web browser. The visitor's web browser will receive content such as the first HTML example (that is, the HTML code without the FreeMarker directive), and the visitor will not be aware of the use of FreeMarker on the server side. (Template files stored on the Web server are not modified; substitutions only appear in the Web server's response.)
The entire data prepared for the template is called a data model. The data model is a tree structure (just like folders and files on a hard disk). In terms of visual effects, The data model can be (this is just a visualization, the data model is not in text format, it comes from Java objects):
In earlier versions, these values could be selected from the data model using the user and latestProduct.name expressions. Analogous to the tree structure of a hard disk, the data model is like a file system. "(root)" and latestProduct correspond to directories (folders), and user, url, and name are files in these directories.
Generally speaking, templates and data models are necessary components for FreeMarker to generate output: template + data model = output.
FreeMarker update log
1. Optimized some functions
2. Solved many unbearable bugs
Huajun editor recommends:
FreeMarker has always been a commonly used programming development software for most friends. It has such a dominant position in the minds of netizens. The editor of Huajun Software Park recommends all users to download FreeMarker. Come and download it. In addition, there areMaven,Java2 Runtime Environment,Eclipse IDE for Java EE Developers For Linux(64-bit),GCC For Linux,Free PascalAvailable for download.





















Useful
Useful
Useful