The Spring MVC allows you to use the @RequestMapping annotation at the class level. This means we can annotate the controller class with @RequestMapping, as shown in the following code snippet:
package com.packt.patterninspring.chapter10.bankapp.web.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping("/") public class HomeController { @RequestMapping(method=GET) public String home() { return "home"; } }
As you have seen in the preceding code, the HomeController class is annotated with the @RequestMapping and @Controller annotations. But the HTTP method is still defined above the handler methods. Class-level mapping is applied with all the handler methods defined under this controller.
After the Spring MVC configuration, we created a controller class with the handler methods. Let's test this controller before moving ahead with more details. In this book, I haven't use any JUnit test cases, so here, I will just run this web application on the Tomcat container. You can see the output on the browser as follows:
The last image is the homepage of our Bank Management System web application.
In the next section, we'll see how to define the handler methods, and the return type and parameters allowed for the handler methods in Spring MVC.