Java logo Spring Boot CRUD project

Overview

In this project I get to build a CRUD system that is a REST API.

The stack used in this project are:

  • Java : Language
  • Spring Boot : Java Framework
  • PostgreSQL : Database

System Flow

Spring Boot

With Spring boot we start by setting up the dependencies from Spring Boot Initializr as shown below

we then download the generated codebase and load it onto our IDE (I use Intellij).

looking at our codebase, we can see the bare-bones Java application, which liiks like the below code-base:

							
package com.example.backendApi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BackendApiApplication {

	public static void main(String[] args) {
		SpringApplication.run(BackendApiApplication.class, args);
	}
}				
					
					

Running the application will then start the tomcat web-server which can be accessed from localhost:8080 as shown below.



We then create the application structure, which in this case is a student API.

The student shall have the following parameters:

  1. id
  2. name
  3. email
  4. age
  5. dob

Create a student package where we shall put all the code that is student related, ie:

  • Student Class : our model
  • StudentController Class : has all the resources for our API
  • StudentService Class : Business logic of managing the students
  • StudentRepository Interface : Acesses your database
  • StudentConfig Class

PostgreSQL DB

To connect to our database, we need to establish a connection between postgres and the the application.

This is done through the spring data jpa, that is loaded into the src/main/resources/application.properties file, which is shown below:

					
spring.datasource.url=jdbc:postgresql://localhost:5432/database
spring.datasource.username=
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true					
					
					

The above will contain the database configurations that shall allow you to connect to the database


© Copyright Kifaru Codes. All Rights Reserved.

Designed by KifaruCodes