类 AbstractCachingViewResolver

    • 方法详细资料

      • setCacheLimit

        public void setCacheLimit​(int cacheLimit)
        Specify the maximum number of entries for the view cache. Default is 1024.
      • getCacheLimit

        public int getCacheLimit()
        Return the maximum number of entries for the view cache.
      • setCache

        public void setCache​(boolean cache)
        Enable or disable caching.

        This is equivalent to setting the "cacheLimit" property to the default limit (1024) or to 0, respectively.

        Default is "true": caching is enabled. Disable this only for debugging and development.

      • isCache

        public boolean isCache()
        Return if caching is enabled.
      • setCacheUnresolved

        public void setCacheUnresolved​(boolean cacheUnresolved)
        Whether a view name once resolved to null should be cached and automatically resolved to null subsequently.

        Default is "true": unresolved view names are being cached, as of Spring 3.1. Note that this flag only applies if the general "cache" flag is kept at its default of "true" as well.

        Of specific interest is the ability for some AbstractUrlBasedView implementations (FreeMarker, Velocity, Tiles) to check if an underlying resource exists via AbstractUrlBasedView.checkResource(Locale). With this flag set to "false", an underlying resource that re-appears is noticed and used. With the flag set to "true", one check is made only.

      • isCacheUnresolved

        public boolean isCacheUnresolved()
        Return if caching of unresolved views is enabled.
      • resolveViewName

        public View resolveViewName​(String viewName,
                                    Locale locale)
                             throws Exception
        从接口复制的说明: ViewResolver
        Resolve the given view by name.

        Note: To allow for ViewResolver chaining, a ViewResolver should return null if a view with the given name is not defined in it. However, this is not required: Some ViewResolvers will always attempt to build View objects with the given name, unable to return null (rather throwing an exception when View creation failed).

        指定者:
        resolveViewName 在接口中 ViewResolver
        参数:
        viewName - name of the view to resolve
        locale - Locale in which to resolve the view. ViewResolvers that support internationalization should respect this.
        返回:
        the View object, or null if not found (optional, to allow for ViewResolver chaining)
        抛出:
        Exception - if the view cannot be resolved (typically in case of problems creating an actual View object)
      • getCacheKey

        protected Object getCacheKey​(String viewName,
                                     Locale locale)
        Return the cache key for the given view name and the given locale.

        Default is a String consisting of view name and locale suffix. Can be overridden in subclasses.

        Needs to respect the locale in general, as a different locale can lead to a different view resource.

      • removeFromCache

        public void removeFromCache​(String viewName,
                                    Locale locale)
        Provides functionality to clear the cache for a certain view.

        This can be handy in case developer are able to modify views (e.g. Velocity templates) at runtime after which you'd need to clear the cache for the specified view.

        参数:
        viewName - the view name for which the cached view object (if any) needs to be removed
        locale - the locale for which the view object should be removed
      • clearCache

        public void clearCache()
        Clear the entire view cache, removing all cached view objects. Subsequent resolve calls will lead to recreation of demanded view objects.
      • loadView

        protected abstract View loadView​(String viewName,
                                         Locale locale)
                                  throws Exception
        Subclasses must implement this method, building a View object for the specified view. The returned View objects will be cached by this ViewResolver base class.

        Subclasses are not forced to support internationalization: A subclass that does not may simply ignore the locale parameter.

        参数:
        viewName - the name of the view to retrieve
        locale - the Locale to retrieve the view for
        返回:
        the View instance, or null if not found (optional, to allow for ViewResolver chaining)
        抛出:
        Exception - if the view couldn't be resolved
        另请参阅:
        resolveViewName(java.lang.String, java.util.Locale)