Creating a CRUD REST API with Spring Boot and PostgreSQL: A Step-by-Step Guide ๐Ÿชœ

ยท

1 min read

Hello Jhipsters (Java-hipsters) ๐Ÿ‘“

In this article we are returning to the basics. We'll be creating a Spring Boot application with a CRUD REST API for product management, using Java 17 and PostgreSQL.

We will use Java's Optional to handle potential null values, enhancing the clarity of our code (you can read more about Optionals in the previous article)

Prerequisites

Folder Structure

Our final folder structure will be something like this

ProductdemoApplication/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main/
โ”‚   โ”‚   โ”œโ”€โ”€ java/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ net/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ camelcodes/
โ”‚   โ”‚   โ”‚           โ”œโ”€โ”€ ProductdemoApplication.java 
โ”‚   โ”‚   โ”‚           โ”œโ”€โ”€ controller/
โ”‚   โ”‚   โ”‚           โ”‚   โ””โ”€โ”€ ProductController.java
โ”‚   โ”‚   โ”‚           โ”œโ”€โ”€ model/
โ”‚   โ”‚   โ”‚           โ”‚   โ””โ”€โ”€ Product.java
โ”‚   โ”‚   โ”‚           โ”œโ”€โ”€ repository/
โ”‚   โ”‚   โ”‚           โ”‚   โ””โ”€โ”€ ProductRepository.java
โ”‚   โ”‚   โ”‚           โ””โ”€โ”€ service/
โ”‚   โ”‚   โ”‚               โ””โ”€โ”€ ProductService.java
โ”‚   โ”‚   โ””โ”€โ”€ resources/
โ”‚   โ”‚       โ””โ”€โ”€ application.properties
โ”‚   โ””โ”€โ”€ test/
โ”‚
โ”œโ”€โ”€ build.gradle
โ””โ”€โ”€ settings.gradle

Click here to read the full article on the new blog

ย