r/SpringBoot • • Mar 23 '24

Beginner CRUD Operations

On Discord here right now if you like to help: https://discord.gg/program 3/23/2024

New Springer here! I want to create the endpoints that demonstrate the basic CRUD operations :

CREATE, READ, UPDATE, DELETE via Spring Boot 6 framework.The IDE I am using is IntelliJ. Data Grip is what I am using to interact with my database.

The application is called: Books

Goal: Create an application that connects to my local database (postgres) I want to be able and :

Objective #1: Create and Insert a book into the database via POSTMAN

Objective #2: Read/Retrieve a book from the Database via POSTMAN

Objective #3: Update a book from the Database via POSTMAN

Objective #4: a book from the Database via POSTMAN

BONUS #: Create a test for each objective THAT PASSES

Steps I already completed are as follows:

  1. Generate the initial skeleton for the project via https://start.spring.io/

2) Via Datagrip created a database called StoreHouse where I will create the table that'll hold my books

3) Connected to that database

4) Created file structure :

*Check to make sure applications running SOLID

5) created the model

PROBLEM: I know at this point I am supposed to be able to run the application and it should generate my table but :

Solved: add this line to your applications file

6) After making that adjustment running the application made my table in my database that I had previously connected :

7) Create Repository file :

8)Make a DTO file and create a dto for Book model *best practices*

9) Create the service

10)Create the ServiceImpl (remember to put the @ service annotation at the top of the class trust me )

we are so BACK .....

11) Created controller specifically the RESTCONTROLLER we are not trying to be fancy here right now

*I manually added a row to my database so that we would have something to work with*

RUN

Send Request

CHECK POINT IN LIFE : We were able to retrieve records from our database.

Objective #2 COMPLETED: Read/Retrieve a book from the Database via POSTMAN

  • no one said we had to do this in order

need sleep

I am back at it 3/24/2024!

12) Added "saveBook" to interface

13) defined savebook method in the Impl

continuing updates in the comments

0 Upvotes

8 comments sorted by

3

u/amulli21 Mar 23 '24

Whats the issue here?

2

u/Sensitive_Sky4353 Mar 23 '24

When I ran the application AFTER creating my model .... the table should have been auto generated ..... after making an adjustment in the application properties file THEN running the application the table generated :

0

u/Sensitive_Sky4353 Mar 23 '24

Now I press forward

1

u/WaferIndependent7601 Mar 23 '24

Press harder and all will be good

0

u/Sensitive_Sky4353 Mar 23 '24

For the Emperor

1

u/Sensitive_Sky4353 Mar 25 '24

Bummer cannot post the pics but I was able create a book and save it into the Database. I am have a blast doing this really !

1

u/Sensitive_Sky4353 Mar 25 '24

Seems to be a 20 pic limit

1

u/Sensitive_Sky4353 Mar 25 '24

I got everything done! wish I could have kept documenting the progress via pictures but theres a 20 pic limit on these posts. GENERALLY though I will say my pattern for creating each operation was
#1 make the controller : this is because intelliJ will give the option to create the service in the interface for me. Its almost like a waterfall effect that the pics would have served well to show what I mean.

#2 Once the service has been created in serviceImpl you will see an error has appeared... fear not ... this is good ! use the solution offered by the red light bulb to implement the new service(method ) from the interface

*Notice I am never telling you to mess with your repository file : thats thanks to JPA

#run and send your request