How to save data in database using spring boot

Blog
Spread the love

Today we are going to learn create RESTfull APIs using Spring Boot :

A) Create Model class:

  1. Vary first we have to create a model class and some field which have mapped with table in database.
  2. @Entity : This annotation used for the identify the model class.
  3. @Table : this is used for the put the name of table in database.
  4. @Data: This annotation has used for the create Getter, Setter, Constructor, to String methods and for this feature have to add Lombok dependency in pom.xml.
  5. @Id: it is used for make the id in table.
  6. @GenatedValue: It is used for the crate the Id auto increment.

B) Create Repository interface:

  1. Now we will create a interface which is CompanyProfile for the mapping the connect to the database . it will help to manipulate the data in database.
  2. In the interface we use JPARepository which is provided by the JPA. it has all database manipulation predefined methods.
  3. In this method we will pass CompanyProfile which is model class and Id which is in Integer.

C) Create service interface:

  1. We will create the service interface and create the method which will communicate with controller class and service implementation as you can see below.

D) Create service implementation class:

  1. In this call we can white his login related to our business and it will implement the service class as well and override the method of service interface which have to create in service interface
  2. In the service implantation class will mark as @service annotation which can well to identify of service class.
  3. We can @autowire the repository as well which will provide the all predefine JPA method to manipulation of database as well.

E)Create Controller class:

  1. And finally, we will create the controller class which will responsible to get the and send the HTTP and HTTPS methods.
  2. In the Controller class we have to mention as @RestController (@Controller + @ResponseBody) which is the responsible for get the JSON data.
  3. Firstly, have to create the method createCompany and @autowire the CompanyService and with the help of companyService we will call createCompany method which have already created in service class.

Postman request:

extention_2023

bluethinkinc_blog

bluethinkinc_blog

2023-09-14

0

Leave a Reply

Your email address will not be published. Required fields are marked *

Find More Blogs

Customize lead qualification for a seamless experience

Spread the love When the 2024 Release Wave 2 was launched,

Create a Custom Console Command in Spryker

Spread the love In Spryker, developers can create custom

SALESFORCE

Spread the love Salesforce is a cloud-based software

CRUD Operation in Spryker Backoffice with a Custom Module

Spread the love Spryker is a highly flexible and modular

How to create custom module on Spryker for Backoffice?

Spread the love Creating a custom module in Spryker

How to Install Spryker Project with Docker on Local Machine

Spread the love Spryker is a flexible and scalable commerce

How to Add a Custom Tab to the Customer Order Detail Page in Magento 2

Spread the love Adding a custom tab to the Order Detail

Exception Handling in Java

Spread the love Introduction – Exception:An unwanted

How to add custom less file in Magento2

Spread the love Source files *.css included into layout

Spring Boot Microservices

Spread the love Microservices architecture has become

bluethinkinc Blogs