public class FreemarkerUtil extends Object
Utility class for working with FreeMarker.Provides convenience methods to process a FreeMarker template name with a model.
Please put the template files in the templates directory under the resources folder| 构造器和说明 |
|---|
FreemarkerUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
generate(String name,
Object model)
Process the specified FreeMarker template with the given model and write the result to the given Writer
|
static void |
generate(String name,
Object model,
OutputStream outputStream)
Process the specified FreeMarker template with the given model and write the result to the given OutputStream
|
static void |
generate(String name,
Object model,
Writer writer)
Process the specified FreeMarker template with the given model and write the result to the given Writer
|
void |
setConfiguration(freemarker.template.Configuration configuration)
Set freemarker template configuration
|
public static String generate(String name, Object model) throws IOException, freemarker.template.TemplateException
name - the template namemodel - the holder of the variables visible from the template (name-value pairs); usually a
Map<String, Object> or a JavaBean (where the JavaBean properties will be the variables)IOExceptionfreemarker.template.TemplateExceptionpublic static void generate(String name, Object model, Writer writer) throws IOException, freemarker.template.TemplateException
name - the template namemodel - the holder of the variables visible from the template (name-value pairs); usually a
Map<String, Object> or a JavaBean (where the JavaBean properties will be the variables)writer - The Writer where the output of the template will go. Note that unless you have used
Configurable.setAutoFlush(boolean) to disable this, Writer.flush() will be called at
the when the template processing was finished. Writer.close() is not called. Can't be
null.IOExceptionfreemarker.template.TemplateExceptionpublic static void generate(String name, Object model, OutputStream outputStream) throws IOException, freemarker.template.TemplateException
name - the template namemodel - the holder of the variables visible from the template (name-value pairs); usually a
Map<String, Object> or a JavaBean (where the JavaBean properties will be the variables)outputStream - the given OutputStreamIOExceptionfreemarker.template.TemplateException@Autowired public void setConfiguration(freemarker.template.Configuration configuration)
configuration - the freemarker template configurationCopyright © 2020. All rights reserved.