Locale; import freemarker. Configuration; import freemarker. Template; import freemarker. TemplateExceptionHandler; import freemarker. File ;. FileWriter ;. OutputStreamWriter ;. Writer ;. ArrayList ;. List ;. HashMap ;. Map ;. Locale ;. Configuration ;.
Template ;. TemplateExceptionHandler ;. Version ;. Pin It on Pinterest. File ; import java. FileWriter ; import java. OutputStreamWriter ; import java. Writer ; import java. ArrayList ; import java. List ; import java. HashMap ; import java. Map ; import java.
Locale ; import freemarker. Configuration ; import freemarker. Template ; import freemarker. However, the output can be directed to any type of Writer, depending on the purpose of the application. Some might argue that the OutputStreamWriter is outdated and we should use the new Writers from Java. If this is not done, then Java will just use whatever charset it detects on your operating system.
This might cause issues with non-ASCII characters displaying incorrectly in the resulting html files. We need to go through the configuration in order to obtain the required template. Once we have it, we can call the template. The whole process can be summarized in the following diagram:.
Let us try out our program by triggering the FreemarkerTemplateWriter bean. Our example is a simple illustration of what could be done with Freemarker and Spring. The output can be directed to a network stream and the data could be obtained from the database. Or the generated html files could be used in a Spring web MVC application for displaying database or other contents.
This example is just a starting point for a really powerful framework. Contents hide. The Freemarker engine needs three components. Multipurpose and lightweight: Zero dependencies, any output format, can load templates from any place pluggable , many configuration options. Versatile data-model: Java objects are exposed to the template as a tree of variables through pluggable adapters, which decides how the template sees them.
See the license here Note that the project is owned by the Apache Software Foundation since 2. Earlier releases, such as 2. Last generated: GMT.
0コメント