public class ControllerClassNameHandlerMapping extends AbstractControllerUrlHandlerMapping
HandlerMapping that
follows a simple convention for generating URL path mappings from the class names
of registered Controller beans
as well as @Controller annotated beans.
For simple Controller implementations
(those that handle a single request type), the convention is to take the
short name of the Class,
remove the 'Controller' suffix if it exists and return the remaining text, lower-cased,
as the mapping, with a leading /. For example:
WelcomeController -> /welcome*HomeController -> /home*For MultiActionControllers and @Controller
beans, a similar mapping is registered, except that all sub-paths are registered
using the trailing wildcard pattern /*. For example:
WelcomeController -> /welcome, /welcome/*CatalogController -> /catalog, /catalog/*For MultiActionController it is often useful to use
this mapping strategy in conjunction with the
InternalPathMethodNameResolver.
Thanks to Warren Oliver for suggesting the "caseSensitive", "pathPrefix" and "basePackage" properties which have been added in Spring 2.5.
Controller,
MultiActionControllerloggerBEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTEHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| Constructor and Description |
|---|
ControllerClassNameHandlerMapping() |
| Modifier and Type | Method and Description |
|---|---|
protected String[] |
buildUrlsForHandler(String beanName,
Class<?> beanClass)
Abstract template method to be implemented by subclasses.
|
protected String[] |
generatePathMappings(Class<?> beanClass)
Generate the actual URL paths for the given controller class.
|
void |
setBasePackage(String basePackage)
Set the base package to be used for generating path mappings,
including all subpackages underneath this packages as path elements.
|
void |
setCaseSensitive(boolean caseSensitive)
Set whether to apply case sensitivity to the generated paths,
e.g.
|
void |
setPathPrefix(String prefixPath)
Specify a prefix to prepend to the path generated from the controller name.
|
determineUrlsForHandler, isControllerType, isEligibleForMapping, isMultiActionControllerType, setExcludedClasses, setExcludedPackages, setIncludeAnnotatedControllersdetectHandlers, initApplicationContext, setDetectHandlersInAncestorContextsbuildPathExposingHandler, exposePathWithinMapping, exposeUriTemplateVariables, getHandlerInternal, getHandlerMap, getRootHandler, lookupHandler, registerHandler, registerHandler, setLazyInitHandlers, setRootHandler, supportsTypeLevelMappings, validateHandleradaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initInterceptors, setAlwaysUseFullPath, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelpergetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextgetApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContextpublic void setCaseSensitive(boolean caseSensitive)
Default is "false", using pure lower case paths, e.g. turning the class name "BuyForm" into "buyform".
public void setPathPrefix(String prefixPath)
Default is a plain slash ("/"). A path like "/mymodule" can be specified in order to have controller path mappings prefixed with that path, e.g. "/mymodule/buyform" instead of "/buyform" for the class name "BuyForm".
public void setBasePackage(String basePackage)
Default is null, using the short class name for the
generated path, with the controller's package not represented in the path.
Specify a base package like "com.mycompany.myapp" to include subpackages
within that base package as path elements, e.g. generating the path
"/mymodule/buyform" for the class name "com.mycompany.myapp.mymodule.BuyForm".
Subpackage hierarchies are represented as individual path elements,
e.g. "/mymodule/mysubmodule/buyform" for the class name
"com.mycompany.myapp.mymodule.mysubmodule.BuyForm".
protected String[] buildUrlsForHandler(String beanName, Class<?> beanClass)
AbstractControllerUrlHandlerMappingbuildUrlsForHandler in class AbstractControllerUrlHandlerMappingbeanName - the name of the beanbeanClass - the type of the beanprotected String[] generatePathMappings(Class<?> beanClass)
Subclasses may choose to customize the paths that are generated by overriding this method.
beanClass - the controller bean class to generate a mapping for