Package com.example.springrest.controllers
package com.example.springrest.controllers
REST controllers that define the public API of the application.
Controllers are the entry point for HTTP requests. They expose
CRUD operations on domain entities (like Product) as REST endpoints.
Each controller delegates business logic to the service layer
and transforms entities into DTOs for client-safe responses.
Responsibilities
- Map HTTP requests to service calls using
@RequestMappingand its variants. - Apply validation on request bodies and parameters (e.g.,
@Valid,@Min). - Return appropriate response entities with status codes and payloads.
- Document endpoints with Swagger/OpenAPI annotations.
Notes
-
Parameter-level validations (e.g.,
@Minon IDs) are shown in early chapters but will only be fully enforced when@Validatedand method validation mare introduced in Part III. -
Exception handling is not done directly in controllers — instead,
GlobalExceptionHandlercentralizes error handling for consistency.
Example
GET /api/products?page=0&size=20
POST /api/products {"name":"Coffee Mug","price":12.99}
-
Classes