#21 Project using Spring | Project Setup with Model
Building the Backend for an E-commerce Application
Setting Up the Project
- The session focuses on building the backend for an e-commerce application after completing the frontend.
- A new Spring Boot web project is created with Maven, using Java version 21 and group ID
comiso.
- Key dependencies include Spring Web, JPA for database connectivity, Dev Tools for fast reload, Lombok for boilerplate code reduction, and H2 as a lightweight database.
Initial Configuration
- The project is unzipped and opened in IntelliJ IDEA Community Edition; default port number set to 8080.
- Before making changes, it's essential to check if port 8080 is available; it runs successfully on port 880.
Database Setup
- Database properties are configured: setting up URL for H2 database and specifying driver class name.
- JPA settings are adjusted to show SQL queries during execution; table creation options are discussed (create vs. update).
Defining Product Model
- Discussion on defining product attributes such as ID (primary key), name, description, brand, price (as BigDecimal), category, release date (formatted), availability (Boolean), and quantity.
- A model package structure is established to organize classes effectively; a product class will be created with specified attributes.
Creating Controller and Testing Endpoints
- A simple REST controller named
ProductControlleris created with a greeting method returning "Hello World" at the base API endpoint.
- Testing the endpoint via Postman or browser confirms that the application responds correctly with "Hello World".
Finalizing Product Class Structure
- The product class is defined with all necessary properties using Lombok annotations for automatic getter/setter generation.
- The product entity must be annotated properly so that JPA recognizes it as a database entity.
Verifying Database Table Creation
- After running the application again, verification of table creation in H2 console shows correct structure but no data yet present.
Conclusion of Current Session
- The session concludes by confirming that the project structure is ready; future sessions will focus on adding data to populate tables.