类 ContentNegotiatingViewResolver

  • 所有已实现的接口:
    Aware, InitializingBean, ApplicationContextAware, Ordered, ServletContextAware, ViewResolver

    public class ContentNegotiatingViewResolver
    extends WebApplicationObjectSupport
    implements ViewResolver, Ordered, InitializingBean
    Implementation of ViewResolver that resolves a view based on the request file name or Accept header.

    The ContentNegotiatingViewResolver does not resolve views itself, but delegates to other ViewResolvers. By default, these other view resolvers are picked up automatically from the application context, though they can also be set explicitly by using the viewResolvers property. Note that in order for this view resolver to work properly, the order property needs to be set to a higher precedence than the others (the default is Ordered.HIGHEST_PRECEDENCE).

    This view resolver uses the requested media type to select a suitable View for a request. The requested media type is determined through the configured ContentNegotiationManager. Once the requested media type has been determined, this resolver queries each delegate view resolver for a View and determines if the requested media type is compatible with the view's content type). The most compatible view is returned.

    Additionally, this view resolver exposes the defaultViews property, allowing you to override the views provided by the view resolvers. Note that these default views are offered as candidates, and still need have the content type requested (via file extension, parameter, or Accept header, described above).

    For example, if the request path is /view.html, this view resolver will look for a view that has the text/html content type (based on the html file extension). A request for /view with a text/html request Accept header has the same result.

    从以下版本开始:
    3.0
    作者:
    Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev
    另请参阅:
    ViewResolver, InternalResourceViewResolver, BeanNameViewResolver