Spring Boot CRUD project
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
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:
Create a student package where we shall put all the code that is student related, ie:
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