How nguyenngocthanhsang/spring-mvc-crud-demo works
Project Type and Purpose
• This is a simple full-stack web application built with Spring MVC. Its primary purpose is to demonstrate CRUD operations (Create, Read, Update, Delete) on Student records using an in-memory data store and JSP views. It follows the classical MVC pattern with Java-based configuration and no external database.
Main Architectural Components
a. Client Layer
• Browser/Client that issues HTTP requests (e.g., GET /student/list, POST /student/save).
b. Web Server & Dispatcher
• Embedded Jetty (invoked via mvn jetty:run) or any Servlet container.
• DispatcherServlet (registered by AppInitializer) receives all incoming requests.
c. Configuration
• AppInitializer.java – replaces web.xml, bootstraps Spring’s DispatcherServlet.
• AppConfig.java – configures ViewResolver, static resource handling, component scanning.
d. Controller Layer (com.group10.controller)
• HomeController – handles root and home page requests.
• StudentController – handles CRUD endpoints (list, showFormForAdd, showFormForUpdate, saveStudent, delete).
e. Service/DAO Layer (com.group10.dao)
• StudentDAO interface defines CRUD signatures.
• StudentDAOImpl – in-memory implementation using ArrayList<Student>.
f. Model Layer (com.group10.model)
• Student – simple POJO with fields id, firstName, lastName, email, dateOfBirth.
g. View Layer (src/main/webapp/WEB-INF/view)
• JSP files (home.jsp, list-students.jsp, student-form.jsp) using Spring Form Tags and JSTL to render HTML.
h. Static Resources (/resources/css/style.css)
• Served via resource handler defined in AppConfig.
Relationships and Data Flow
1. Client Browser → HTTP Request → Jetty Container → DispatcherServlet
2. DispatcherServlet → HandlerMapping → identified Controller method
3. Controller → invokes StudentDAO methods (injected via @Autowired)
4. DAO → updates in-memory ArrayList<Student>
5. Controller → populates Spring Model with data, returns view name (list-students)
6. ViewResolver → resolves JSP path
7. JSP → renders HTML/CSS, sends HTTP Response back to Client
Architectural Patterns and Principles
• MVC (Model-View-Controller) separation.
• Java-based configuration (no XML) using @Configuration + @EnableWebMvc.
• Dependency Injection with @Autowired.
• Annotation-driven request mapping (@Controller, @RequestMapping).
• PRG (Post/Redirect/Get) pattern for form submission.
• In-memory data store for demo simplicity.