Spring MVC ControllerClassNameHandlerMapping tutorial with example


What is ControllerClassNameHandlerMapping

        Implementation of HandlerMapping that follows a simple convention for generating URL path mappings from the class names of registered Controller 

        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*


Example

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <!-- ************************************************************* -->
 	<!-- which handler mapping used here ControllerClassNameHandlerMapping -->  
      
	<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
	 	<property name="caseSensitive" value="true"/>    
	 	<property name="pathPrefix" value="/customer" />   
	</bean>  
	<!-- ************************************************************* -->   
	<!-- which resolver used here InternalResourceViewResolver -->
	 
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" >	    
		            
		<property name="prefix">
		    <!-- location of jsp pages -->
		    
			<value>/WEB-INF/pages/</value>
		</property>
		<!-- extension of jspfiles -->
		
		<property name="suffix">
		 	<value>.jsp</value>
		</property>    
	    
	</bean>
	
	<!-- ************************************************************* -->
	<!-- which controller used here BeanNameUrlHandlerMappingController created by us -->
	
	<bean class="com.candidjava.springmvc.ControllerClassNameHandlerMappingController" />
	
	<!-- ************************************************************* -->
</beans>

ScreenShot

            

                        

Download

ControllerClassNameHandlerMapping maven zip

ControllerClassNameHandlerMapping war



Comments


©candidjava.com