Book Image

Spring MVC: Beginner's Guide - Second Edition

By : Amuthan Ganeshan
Book Image

Spring MVC: Beginner's Guide - Second Edition

By: Amuthan Ganeshan

Overview of this book

Spring MVC helps you build flexible and loosely coupled web applications. The Spring MVC Framework is architected and designed in such a way that every piece of logic and functionality is highly configurable. Also, Spring can integrate effortlessly with other popular web frameworks such as Struts, WebWork, Java Server Faces, and Tapestry. The book progressively teaches you to configure the Spring development environment, architecture, controllers, libraries, and more before moving on to developing a full web application. It begins with an introduction to the Spring development environment and architecture so you're familiar with the know-hows. From here, we move on to controllers, views, validations, Spring Tag libraries, and more. Finally, we integrate it all together to develop a web application. You'll also get to grips with testing applications for reliability.
Table of Contents (20 chapters)
Spring MVC Beginner's Guide - Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Default request mapping method


Every Controller class can have one default request mapping method. What is the default request mapping method? If we simply don't specify any request path value in the @RequestMapping annotation of a Controller's method, that method is designated as the default request mapping method for that class. So whenever a request URL just ends up with the Controller's class level request path value without any further relative path down the line, then Spring MVC will invoke this method as a response to that request.

Tip

If you specify more than one default mapping method inside a Controller, you will get IllegalStateException with the message Ambiguous mapping found. So a Controller can have only one default request mapping method at most.

Why not change the welcome method to the default request mapping method for our HomeController class?

  1. In the HomeController class, add the following annotation on top of the class:

          @RequestMapping("/") 
    
  2. And from the welcome...