## org.springframework.web.servlet.mvc.support
Class ControllerClassNameHandlerMapping

    java.lang.Object
      org.springframework.context.support.ApplicationObjectSupport
          org.springframework.web.context.support.WebApplicationObjectSupport
              org.springframework.web.servlet.handler.AbstractHandlerMapping
                  org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
                      org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping
                          org.springframework.web.servlet.mvc.support.AbstractControllerUrlHandlerMapping
                              org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping

All Implemented Interfaces:
  ApplicationContextAware, Ordered, ServletContextAware, HandlerMapping

    public class ControllerClassNameHandlerMapping

extends AbstractControllerUrlHandlerMapping

Implementation of `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.

Since:
  2.0
Author:
  Rob Harrop, Juergen Hoeller
See Also:
  `Controller`, `MultiActionController`

Field Summary

Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
`logger`

Fields inherited from interface org.springframework.web.servlet.HandlerMapping
`BEST_MATCHING_PATTERN_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE`

Fields inherited from interface org.springframework.core.Ordered
`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

Constructor Summary
`ControllerClassNameHandlerMapping()`

Method Summary
`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.

Methods inherited from class org.springframework.web.servlet.mvc.support.AbstractControllerUrlHandlerMapping
`determineUrlsForHandler, isControllerType, isEligibleForMapping, isMultiActionControllerType, setExcludedClasses, setExcludedPackages, setIncludeAnnotatedControllers`

Methods inherited from class org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping
`detectHandlers, initApplicationContext, setDetectHandlersInAncestorContexts`

Methods inherited from class org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
`buildPathExposingHandler, exposePathWithinMapping, exposeUriTemplateVariables, getHandlerInternal, getHandlerMap, getPathMatcher, getRootHandler, initInterceptors, lookupHandler, registerHandler, registerHandler, setAlwaysUseFullPath, setLazyInitHandlers, setMappedInterceptors, setPathMatcher, setRootHandler, setUrlDecode, setUrlPathHelper, validateHandler`

Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
`adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, setDefaultHandler, setInterceptors, setOrder`

Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
`getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext`

Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
`getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ControllerClassNameHandlerMapping

    public ControllerClassNameHandlerMapping()

Method Detail

### setCaseSensitive

    public void setCaseSensitive(boolean caseSensitive)

  Set whether to apply case sensitivity to the generated paths, e.g. turning the class name "BuyForm" into "buyForm".

  Default is "false", using pure lower case paths, e.g. turning the class name "BuyForm" into "buyform".

### setPathPrefix

    public void setPathPrefix(String prefixPath)

  Specify a prefix to prepend to the path generated from the controller name.

  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".

### setBasePackage

    public void setBasePackage(String basePackage)

  Set the base package to be used for generating path mappings, including all subpackages underneath this packages as path elements.

  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".

### buildUrlsForHandler

    protected String[] buildUrlsForHandler(String beanName,
                                           Class beanClass)

  Description copied from class: `AbstractControllerUrlHandlerMapping`
  Abstract template method to be implemented by subclasses.

  Specified by:
    `buildUrlsForHandler` in class `AbstractControllerUrlHandlerMapping`
  Parameters:
    `beanName` - the name of the bean
    `beanClass` - the type of the bean
  Returns:
    the URLs determined for the bean

### generatePathMappings

    protected String[] generatePathMappings(Class beanClass)

  Generate the actual URL paths for the given controller class.

  Subclasses may choose to customize the paths that are generated by overriding this method.

  Parameters:
    `beanClass` - the controller bean class to generate a mapping for
  Returns:
    the URL path mappings for the given controller