public class ViewControllerRegistry extends Object
Constructor and Description |
---|
ViewControllerRegistry(ApplicationContext applicationContext)
Class constructor with
ApplicationContext . |
Modifier and Type | Method and Description |
---|---|
RedirectViewControllerRegistration |
addRedirectViewController(String urlPath,
String redirectUrl)
Map a view controller to the given URL path or pattern in order to redirect
to another URL.
|
void |
addStatusController(String urlPath,
HttpStatus 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.
|
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. |
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. |
public ViewControllerRegistry(@Nullable ApplicationContext applicationContext)
ApplicationContext
.public ViewControllerRegistration addViewController(String urlPathOrPattern)
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.
public RedirectViewControllerRegistration addRedirectViewController(String urlPath, String redirectUrl)
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.
public void addStatusController(String urlPath, HttpStatus statusCode)
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.
public void setOrder(int order)
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.
@Nullable protected SimpleUrlHandlerMapping buildHandlerMapping()
HandlerMapping
that contains the registered view
controller mappings, or null
for no registrations.