📘Spring Boot Controller for Displaying Student Data with Thymeleaf This Spring Boot controller is part of a web application that showcases student information using a clean MVC architecture. While the current implementation uses hardcoded data, it lays the foundation for integrating a SQL database for dynamic content retrieval.
🔧 Key Components
- Package: com.training.Controller Organizes the controller logic for handling web requests.
- Class: Control Annotated with @Controller, this class defines a web endpoint to serve student data to the frontend.
- Method: hello(Model model)
- Mapped to the /show URL using @GetMapping.
- Creates a list of Stu objects (representing students).
- Adds the list to the model using model.addAttribute("list", list), making it accessible to the Thymeleaf template named show.html.
🧩 Integration with Thymeleaf
- The show.html template can iterate over the list using Thymeleaf’s th:each directive to render student details dynamically.
- Example usage in the template:
🗃️ SQL Database Integration (Next Step)
To connect this setup to a SQL database:
- Replace the hardcoded list with a service that fetches data using Spring Data JPA.
- Define a StuRepository interface extending JpaRepository.
- Inject the repository into the controller and use repository.findAll() to populate the list.
// IMAGE SHOWING THAT MY SQL IS LINKED WITH MY SPRING APPLICATION.