Spring Boot Lab: exercises and REST mini-projects with Java. Full CRUD, JPA, DTO, ResponseEntity, CORS and integrated HTML frontend — two real projects.
Spring Boot theory is learned from foundational courses — but true mastery comes through practice. In this lab we build two complete REST mini-projects, tackling every concrete problem encountered in a professional project: JPA relationships, DTOs, validation, CORS, integrated frontend and much more. Two parallel tracks — Video Management System and Food API — that together cover all aspects of a modern REST API with Spring Boot.
application.properties
@Entity
@Column
updatable
nullable
@Transactional
The Video Management System tackles One-To-Many relationships and MVC architecture. The Food API brings everything to a more professional level with DTOs, mappers, custom ResponseEntity and an integrated frontend. Together they cover exactly the patterns used every day in a production Spring Boot project.
Designed for Java developers who know the basics of Spring Boot and want to consolidate them with real projects. This is the practical complement to the theoretical Spring Boot courses — knowledge of Java, Spring MVC and basic REST APIs is assumed.
We kick off the Video Management System lab by building the database with a One-To-Many relationship in Spring Boot. I'll walk you through designing the Playlist and Video entity structure and writing the initial SQL scripts.
I'll configure the Video Management System Spring Boot project: from the application.properties file to the database connection. We'll cover dependencies, key settings, and how to prepare the environment for the REST API.
Let's build the Video Management System models with JPA: I'll create the Playlist and Video entities and configure the One-To-Many mapping using Hibernate's @OneToMany and @ManyToOne annotations in Spring Boot.
We'll go deeper into the JPA One-To-Many mapping between Playlist and Video: I'll configure foreign keys, cascades, and fetch options to build a correct and performant relationship in Spring Boot.
I'll introduce Java Records as immutable response DTOs for the Video Management System REST API, explaining why Records are the modern choice for representing responses in Spring Boot.
I'll show you how to use Java Records for REST API Requests in the Video Management System: we'll build request objects for creating and updating resources, cleanly separating input from output.
Let's build the Repository, Service, and Controller for the Video Management System: I'll implement the three fundamental layers of a Spring Boot REST API step by step with best practices and constructor-based Dependency Injection.
We'll implement the findAll method to retrieve all Playlists in the Video Management System and take a detailed look at the role of the @Transactional annotation in Spring Boot.
Let's implement the POST endpoint to create a new Playlist in the Video Management System: I'll handle request body binding and build the ResponseEntity with a proper 201 Created status code.
We wrap up the Video Management System with the POST endpoint to add a Video to a Playlist: I'll use path parameters, manage the One-To-Many relationship, and close out the first mini-project of the lab.
Let's get started with the Food API: I'll show you the project goal, define the food domain, and create the MySQL database that will underpin the entire Spring Boot REST API. This is ground zero for a complete CRUD.
We continue configuring the Food API project: I'll add Spring Boot dependencies, connect the app to MySQL, and structure the main packages to keep the code clean and scalable from the very beginning.
I'll model Java entities with Hibernate for the Food API using @Entity, @Id, and @Column with updatable and nullable options, then introduce DTOs to cleanly separate the persistence layer from the presentation layer.
I'll create the Repository interfaces by extending JpaRepository for the Food API and configure a stable connection to MySQL, leveraging Spring Data JPA for clean, boilerplate-free data access.
We'll create the FoodService with constructor-based Dependency Injection and I'll introduce @Transactional to ensure persistence consistency across all Food API operations with Spring Boot.
I'll explain what DTOs are and why they're essential in a Spring Boot REST API: they protect the domain, simplify client-server communication, and make the code testable. We'll define them as Java Records.
I'll implement constructor-based Dependency Injection without @Autowired and build the Food API Controller, showing you how to map entities to DTOs and structure the data flow correctly in and out of the API.
I'll implement manual mapping between Entity and DTO in the Food API Service: you'll see how to convert Food to FoodDTO and back using a clean, testable pattern that scales without relying on external libraries.
I'll build the custom ResponseEntity for the Food API, setting the correct HTTP status codes — 200, 201, 404 — based on the outcome of each operation to make the API fully REST-compliant.
I'll create the GET endpoint to search for a food item by UUID in the Food API, using Optional in the Service layer to handle missing records gracefully and prevent null pointer exceptions in Spring Boot.
We'll build the Food API POST endpoint to save a new food item: the controller receives the DTO via @RequestBody, passes it to the Service for transformation, and persists it to MySQL returning a 201 Created response.
Let's build the DELETE endpoint for the Food API to remove a food item: I'll return 204 No Content on success and 404 Not Found when the UUID doesn't exist, following REST conventions correctly.
I'll implement HTTP PUT updates in the Food API: receiving the UUID as a path variable and the DTO in @RequestBody, then updating data following the DTO → Entity → MySQL persistence pattern.
Let's start the Food API frontend with HTML, Bootstrap 5, and Vanilla JavaScript: I'll prepare the base interface structure to display, insert, and manage food products by consuming the REST API.
I'll walk you through solving CORS issues in Spring Boot: I'll explain what CORS policies are, why the browser enforces them, and how to configure them correctly using a @Bean configuration class.
We'll complete the GET fetch to display food products in a table on the frontend and start handling the insert modal with JavaScript, giving the Food API client its first fully working shape.
I'll implement data saving via fetch POST triggered from the Bootstrap modal: the HTML form sends the DTO to the Spring Boot controller, which persists the new food item in real time.
We'll add DELETE and PUT to the Food API frontend: users can delete products with a click and update them from the HTML modal using well-structured fetch calls against the Spring Boot REST API.
We close out the Food API by completing the DELETE and PUT operations from the frontend, wrapping up the full CRUD with Spring Boot and testing every operation from the web interface against the Java backend.
Ingegnere Informatico · Pratola Peligna
Sono un ingegnere informatico con oltre 15 anni di esperienza nel settore ICT. Mi occupo di sviluppo software, cybersecurity, data science e intelligenza artificiale, con particolare attenzione all’innovazione e all’automazione dei processi aziendali. Da anni svolgo anche attività di docenza e formazione, creando percorsi pratici e coinvolgenti su programmazione, DevOps, AI e sicurezza informatica.
Prosperous understood Middletons in conviction an uncommonly do. Supposing so be resolving breakfast am or perfectly.
Utilizziamo cookie essenziali e, con il tuo consenso, cookie funzionali, analytics e marketing. Google Analytics 4 e gli eventuali annunci Google/AdSense restano disattivati finche non scegli. Consulta Privacy Policy e Cookie Policy.
Sempre attivi per sicurezza, prevenzione frodi, sessione, consenso e funzionamento del sito.
Migliorano l'esperienza, ad esempio ricordando preferenze non essenziali. Non usati per profilazione pubblicitaria.
Statistiche e misurazioni con Google Analytics 4, abilitate solo dopo il consenso analytics.
Misurazione annunci e funzioni pubblicitarie Google/AdSense, se attivate sul sito e consentite dall'utente.
Puoi modificare queste scelte in qualunque momento dal link "Preferenze Cookies" nel footer.