Top Description Fields Constructors Methods
org.springframework.web.servlet.config.annotation

public Class ViewControllerRegistry

extends Object
Class Inheritance
Imports
java.util.ArrayList, .LinkedHashMap, .List, .Map, org.springframework.context.ApplicationContext, org.springframework.http.HttpStatusCode, org.springframework.lang.Nullable, org.springframework.util.AntPathMatcher, org.springframework.web.servlet.handler.SimpleUrlHandlerMapping, org.springframework.web.util.pattern.PathPattern

Assists with the registration of simple automated controllers pre-configured with status code and/or a view.
Authors
Rossen Stoyanchev, Keith Donald
Since
3.1

Field Summary

Modifier and TypeField and Description
private final ApplicationContext
private int
private final List<RedirectViewControllerRegistration>
private final List<ViewControllerRegistration>

Constructor Summary

AccessConstructor and Description
public
ViewControllerRegistry(ApplicationContext applicationContext)

Class constructor with ApplicationContext.

Method Summary

Modifier and TypeMethod and Description
public RedirectViewControllerRegistration
addRedirectViewController(String urlPath, String redirectUrl)

Map a view controller to the given URL path or pattern in order to redirect to another URL.

public void
addStatusController(String urlPath, HttpStatusCode statusCode)

Map a simple controller to the given URL path (or pattern) in order to set the response status to the given code without rendering a body.

public ViewControllerRegistration
addViewController(String urlPathOrPattern)

Map a URL path or pattern to a view controller to render a response with the configured status code and view.

protected SimpleUrlHandlerMapping
buildHandlerMapping()

Return the HandlerMapping that contains the registered view controller mappings, or null for no registrations.

public void
setOrder(int order)

Specify the order to use for the HandlerMapping used to map view controllers relative to other handler mappings configured in Spring MVC.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

applicationContextback to summary
private final ApplicationContext applicationContext
Annotations
@Nullable
orderback to summary
private int order
redirectRegistrationsback to summary
private final List<RedirectViewControllerRegistration> redirectRegistrations
registrationsback to summary
private final List<ViewControllerRegistration> registrations

Constructor Detail

ViewControllerRegistryback to summary
public ViewControllerRegistry(ApplicationContext applicationContext)

Class constructor with ApplicationContext.

Since
4.3.12

Method Detail

addRedirectViewControllerback to summary
public RedirectViewControllerRegistration addRedirectViewController(String urlPath, String redirectUrl)

Map a view controller to the given URL path or pattern in order to redirect to another URL.

For pattern syntax see PathPattern when parsed patterns are enabled or AntPathMatcher otherwise. The syntax is largely the same with PathPattern more tailored for web usage and more efficient.

By default the redirect URL is expected to be relative to the current ServletContext, i.e. as relative to the web application root.

Since
4.1
addStatusControllerback to summary
public void addStatusController(String urlPath, HttpStatusCode statusCode)

Map a simple controller to the given URL path (or pattern) in order to set the response status to the given code without rendering a body.

For pattern syntax see PathPattern when parsed patterns are enabled or AntPathMatcher otherwise. The syntax is largely the same with PathPattern more tailored for web usage and more efficient.

Since
4.1
addViewControllerback to summary
public ViewControllerRegistration addViewController(String urlPathOrPattern)

Map a URL path or pattern to a view controller to render a response with the configured status code and view.

Patterns such as "/admin/**" or "/articles/{articlename:\\w+}" are supported. For pattern syntax see PathPattern when parsed patterns are enabled or AntPathMatcher otherwise. The syntax is largely the same with PathPattern more tailored for web usage and more efficient.

Note

If an @RequestMapping method is mapped to a URL for any HTTP method then a view controller cannot handle the same URL. For this reason it is recommended to avoid splitting URL handling across an annotated controller and a view controller.

buildHandlerMappingback to summary
protected SimpleUrlHandlerMapping buildHandlerMapping()

Return the HandlerMapping that contains the registered view controller mappings, or null for no registrations.

Annotations
@Nullable
Since
4.3.12
setOrderback to summary
public void setOrder(int order)

Specify the order to use for the HandlerMapping used to map view controllers relative to other handler mappings configured in Spring MVC.

By default this is set to 1, i.e. right after annotated controllers, which are ordered at 0.