Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Spring Spring3.2 ControllerClassNameHandlerMapping class for handling convention mapping

Related Tutorials


 
 

Share on Google+Share on Google+

ControllerClassNameHandlerMapping class for handling convention mapping

Advertisement
In this section, you will learn about handling mapping in convention style using ControllerClassNameHandlerMapping class.

ControllerClassNameHandlerMapping class for handling convention mapping

In this section, you will learn about handling mapping in convention style using ControllerClassNameHandlerMapping class.

Spring 3.2 supports conventional style mapping through ControllerClassNameHandlerMapping class. You need to configure ControllerClassNameHandlerMapping class in Spring MVC configuration file. This class determines the mapping between request URLs and the Controller, which handle these requests.

The ControllerClassNameHandlerMapping discovers all the Controllers defined in application context and removes the 'Controller' from their name. The resultant name will be the request URL.

For example :

  • WelcomeController maps to the /welcome* request URL

  • HomeController maps to the /home* request URL

To understand it completely, consider a scenario :

Suppose we have a simple controller :

public class FormHandlerController implements Controller {

	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
		// implementation
	}
}

The Spring MVC configuration file contains the related configuration for the above controller :

<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

<bean id="formHandler" class="a.b.c.FormHandlerController ">
	<!-- dependencies -->
</bean>

ControllerClassNameHandlerMapping class finds all the Controller defined in the configuration file and chops the Controller from their name to specify its handler mappings.

In the above case, the ControllerClassNameHandlerMapping class  chops the Controller from its name and define its handler mapping. So the FormHandlerController  maps to the /formhandler* request URL.

You can represent it graphically as :

FormHandlerController -------------maps to------------> /formhandler*

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 28, 2013

Related Tutorials

Discuss: ControllerClassNameHandlerMapping class for handling convention mapping  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com