类 FreeMarkerView

    • 方法详细资料

      • setEncoding

        public void setEncoding​(String encoding)
        Set the encoding of the FreeMarker template file. Default is determined by the FreeMarker Configuration: "ISO-8859-1" if not specified otherwise.

        Specify the encoding in the FreeMarker Configuration rather than per template if all your templates share a common encoding.

      • getEncoding

        protected String getEncoding()
        Return the encoding for the FreeMarker template.
      • setConfiguration

        public void setConfiguration​(freemarker.template.Configuration configuration)
        Set the FreeMarker Configuration to be used by this view.

        If this is not set, the default lookup will occur: a single FreeMarkerConfig is expected in the current web application context, with any bean name. Note: using this method will cause a new instance of TaglibFactory to created for every single FreeMarkerView instance. This can be quite expensive in terms of memory and initial CPU usage. In production it is recommended that you use a FreeMarkerConfig which exposes a single shared TaglibFactory.

      • getConfiguration

        protected freemarker.template.Configuration getConfiguration()
        Return the FreeMarker configuration used by this view.
      • initServletContext

        protected void initServletContext​(ServletContext servletContext)
                                   throws BeansException
        Invoked on startup. Looks for a single FreeMarkerConfig bean to find the relevant Configuration for this factory.

        Checks that the template for the default Locale can be found: FreeMarker will check non-Locale-specific templates if a locale-specific one is not found.

        覆盖:
        initServletContext 在类中 WebApplicationObjectSupport
        参数:
        servletContext - the ServletContext that this application object runs in (never null)
        抛出:
        BeansException
        另请参阅:
        TemplateCache.getTemplate(java.lang.String, java.util.Locale, java.lang.Object, java.lang.String, boolean)
      • getObjectWrapper

        protected freemarker.template.ObjectWrapper getObjectWrapper()
        Return the configured FreeMarker ObjectWrapper, or the default wrapper if none specified.
        另请参阅:
        Configurable.getObjectWrapper()
      • checkResource

        public boolean checkResource​(Locale locale)
                              throws Exception
        Check that the FreeMarker template used for this view exists and is valid.

        Can be overridden to customize the behavior, for example in case of multiple templates to be rendered into a single view.

        覆盖:
        checkResource 在类中 AbstractUrlBasedView
        参数:
        locale - the desired Locale that we're looking for
        返回:
        true if the resource exists (or is assumed to exist); false if we know that it does not exist
        抛出:
        Exception - if the resource exists but is invalid (e.g. could not be parsed)
      • buildTemplateModel

        protected freemarker.template.SimpleHash buildTemplateModel​(Map<String,​Object> model,
                                                                    HttpServletRequest request,
                                                                    HttpServletResponse response)
        Build a FreeMarker template model for the given model Map.

        The default implementation builds a AllHttpScopesHashModel.

        参数:
        model - the model to use for rendering
        request - current HTTP request
        response - current servlet response
        返回:
        the FreeMarker template model, as a SimpleHash or subclass thereof
      • getTemplate

        protected freemarker.template.Template getTemplate​(String name,
                                                           Locale locale)
                                                    throws IOException
        Retrieve the FreeMarker template specified by the given name, using the encoding specified by the "encoding" bean property.

        Can be called by subclasses to retrieve a specific template, for example to render multiple templates into a single view.

        参数:
        name - the file name of the desired template
        locale - the current locale
        返回:
        the FreeMarker template
        抛出:
        IOException - if the template file could not be retrieved
      • processTemplate

        protected void processTemplate​(freemarker.template.Template template,
                                       freemarker.template.SimpleHash model,
                                       HttpServletResponse response)
                                throws IOException,
                                       freemarker.template.TemplateException
        Process the FreeMarker template to the servlet response.

        Can be overridden to customize the behavior.

        参数:
        template - the template to process
        model - the model for the template
        response - servlet response (use this to get the OutputStream or Writer)
        抛出:
        IOException - if the template file could not be retrieved
        freemarker.template.TemplateException - if thrown by FreeMarker
        另请参阅:
        Template.process(Object, java.io.Writer)