Spring Book – Chapter 14 – Spring MVC and Spring Web Flow

With new versions of Spring MVC controllers can be created using the various annotations available like @Controller, @RequestMapping and so on. By Using these annotations, you need not have your controller class extend the various built-in controller classes in Spring MVC.

Creating controller using Spring MVC provided annotation can be summarized as shown below:

  1. Create a simple POJO class and annotate it with @Controller.
  2. Create as may request handling methods as required by your web application.
  3. Now map the URL’s to the appropriate methods using the annotation @RequestMapping.
  4. Implement the method body by first calling appropriate business logic service; populate the Model object with data from the business service and then finally selecting appropriate View object and returning it.

Listing 14-5 below shows a typical controller class created using @Controller annotation and a sample method mapped to appropriate URL.

Listing 14-5. Controller class created using @Controller annotation

The @RequestMapping anotation has multiple options by which to map the URL request from the client. Listing 14-6 below shows this annotation and its various options.

Listing 14-6. @RequestMapping annotation options

Page Visitors: 8091

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *