liveBook · Manning

@requestmapping

As explained in Spring Start Here, Second Edition

Request mapping is the association between an HTTP request pattern and the controller handler that processes it.

@RequestMapping associates a controller action—a method—with a specific HTTP request. Its path value tells Spring which URL should invoke that action. section 7.3

Map the home page

Annotate a controller method with @RequestMapping("/home") and have it return "home.html". A browser request to /home invokes the method, and the app sends the HTML page as its response. section 7.3

Listing 7.5 The definition of the controller class
@Controller    #A
public class MainController {
 
  @RequestMapping("/home")  #B
  public String home() {
    return "home.html";    #C
  }
}

See the complete controller example, including the class annotation, request path, and returned page name. section 7.3

How Spring Start Here, Second Edition covers it

How deep it goes
Defines path-based mapping with a returned view name, while deferring request parameters and alternative annotations.
Examples
Uses a /home mapping that returns home.html for a browser request.
What you can do after
Build a minimal Spring MVC route by mapping a controller method to a path.
How it connects
Connects controller actions with Spring MVC and the HTTP request-response flow.

Also explained in

Compare how 3 books explain @requestmapping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.