liveBook · Manning

Spring MVC

As explained in Spring Start Here, Second Edition

Spring MVC is the Spring web framework for developing applications that handle HTTP requests.

Spring MVC is the part of Spring used to build web applications that handle HTTP requests. It provides components that intercept and manage requests, letting application code focus on what to do with them. section 1.2 section 7.5

A Java web application also needs a servlet container, such as Tomcat, to translate HTTP requests and responses for the application. Spring Boot can configure both the container and Spring MVC components automatically. section 7.5

For a minimal request-response flow:

  • Mark a controller class with @Controller. section 7.5
  • Use @RequestMapping to assign a controller action to an HTTP request. section 7.5
  • Provide an HTML document containing the data to send in the response. section 7.5

Spring MVC also supports REST endpoints. Use @ResponseBody when a controller method returns the response body directly, or use @RestController instead of @Controller. Without either, the dispatcher servlet treats the method’s return value as a view name and looks for that view. section 10.6

A REST endpoint can receive data through request parameters, path variables, or the request body. An action can use Spring’s default response status or return a ResponseEntity to manage the status and headers. Exceptions can be handled in the action or separately in a REST controller advice class, which can help avoid duplicated handling logic. section 10.6

How Spring Start Here, Second Edition covers it

How deep it goes
Summarizes controller configuration, response handling, and exception handling without detailing MVC component internals.
Examples
Uses controller annotations, HTML responses, ResponseEntity, and REST controller advice to illustrate request handling.
What you can do after
Apply it via Spring MVC to configure controller actions and handle REST requests and responses.
How it connects
Connects Spring MVC with servlet containers, Spring Boot autoconfiguration, controllers, REST, and HTTP.

Also explained in

Compare how 4 books explain Spring MVC →

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.