Skip to content

Java SpringBoot app for making CRUD with a real DataBase with PostgreSQL and much more.

Notifications You must be signed in to change notification settings

Mohamed-fawzyy/CRUD-SpringBoot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reach me on

LinkedIn Gmail Facebook

Technology Stack

Project Idea 🎩

This project is a Spring Boot application that demonstrates CRUD (Create, Read, Update, Delete) operations using a PostgreSQL database. The application is designed with best practices for a professional and maintainable codebase, including proper configuration, validation, and exception handling.

Features 🚀

  • CRUD operations: Create, Read, Update, and Delete operations on a Person entity.
  • PostgreSQL integration: Uses PostgreSQL as the database.
  • Validation: Validates input data using @Valid, @NonNull and @NotBlank annotations.
  • Exception Handling: Global exception handling for clean error responses.

Prerequisites 📚

  • Java 17 or higher
  • Maven 3.6.0 or higher
  • PostgreSQL database from Docker
  • Getting Started

Clone the repository 🧑🏽‍💻

git clone https://github.com/your-username/spring-boot-crud-postgresql.git
cd spring-boot-crud-postgresql

Configure the Database 💾

Create a PostgreSQL database and update the connection settings in src/main/resources/application.properties.

spring.datasource.url=jdbc:postgresql://localhost:5432/your_database
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

Run a PostgreSQL container:

docker run --name postgres-db -e POSTGRES_USER=your_username -e POSTGRES_PASSWORD=your_password -e POSTGRES_DB=your_database -p 5432:5432 -d postgres

Build and Run the Application 🛠

./mvnw clean install
./mvnw spring-boot:run

API Endpoints 🗺

  • Get all persons

    • GET /api/v1/person
  • Get person by ID

    • GET /api/v1/person/{id}
  • Add new person

    • POST /api/v1/person
    • Body:
{
  "name": "John Doe"
}
  • Update person
    • PUT /api/v1/person/{id}
    • Body:
{
  "name": "Mohamed Fawzy"
}
  • Delete person
    • DELETE /api/v1/person/{id}

Project Structure🎢

src
├── main
   ├── java
      └── com
          └── example
              └── demo
                  ├── controller
                     └── PersonController.java
                  ├── model
                     └── Person.java
                  ├── datasource
                     └── PostgresDataSource.java
                  ├── service
                     └── PersonService.java
                  └── dao
                      └── PersonDataAccessService.java
                      └── PersonDao.java
   └── resources
       └── application.properties
       └── application.yaml
       └── db
           └── migration
               └── V1__PersonTable.sql
└── test
    └── java
        └── com
            └── example
                └── demo
                    └── DemoApplicationTests.java

Contributing 📝

Contributions are welcome! Please fork the repository and submit a pull request.

About

Java SpringBoot app for making CRUD with a real DataBase with PostgreSQL and much more.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages