Spring MVC

Basic Spring
≈ 2 min read

Spring's web layer: from an HTTP request to Java code

Spring Boot already knows how to start the application and prepare typical infrastructure. Spring MVC adds the web layer: it accepts HTTP requests, routes them to the right code, converts incoming data into Java values, and builds a response for the client. Instead of working with the Servlet API by hand, most common tasks are described with annotations and regular methods.

This section focuses specifically on HTTP request processing. We will connect URLs and HTTP methods to controllers, learn to read request data, return response bodies, validate incoming data, and handle errors centrally.

What is inside this section

  • Spring MVC Basics. We will build the overall picture of the web layer and the request path through the application.
  • DispatcherServlet. We will examine the central point through which Spring MVC coordinates request processing.
  • Controllers. We will learn to define classes that accept web requests and delegate work to the rest of the application.
  • Request Mapping. We will connect URLs and HTTP methods to specific controller methods.
  • Request Parameters. We will obtain values from query parameters and path variables.
  • RequestBody and ResponseBody. We will connect HTTP request and response bodies with Java objects.
  • REST Controllers. We will combine the mechanisms we have learned into a familiar REST controller.
  • Validation. We will check incoming data before business logic runs.
  • Exception Handling. We will turn application errors into predictable HTTP responses.
  • Filters and Interceptors. We will see two request interception levels for shared infrastructure logic.
  • HttpMessageConverters. We will understand which mechanism turns an HTTP message body into a Java object and back.

The topics follow the path of a real request: from entering Spring MVC to controller arguments and the final HTTP response. After this section, you will understand not only how to write an endpoint, but also which Spring MVC parts participate in its work.