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

Proxy Design Pattern and Requisition List in Magento 2

Spread the love Requisition List in Magento 2 Requisition

Google Ads Conversion Tracking Through Magento Platform:

Spread the love Google Ads Conversion Tracking Through

Object Pool Pattern in Magento2

Spread the love What is Object Pool Pattern in Magento 2 An

JENKINS

Spread the love JENKINS Introduction and Installation

Virtual Type and Type

Spread the love Virtual type is one of the most common

Customize the length of Input field

Spread the love Sometimes we need to change the limit the

How to Add Custom Tab on Admin Dashboard and Count Website Total Visitor in Magento 2?

Spread the love In this blog we’ll see How to Add Custom

How to Add Sign Out Tab in Customer Account in Magento 2?

Spread the love In this blog we’ll see How to Add

How to create custom tab in product detail page in magento 2?

Spread the love In this blog we’ll see how to add

Understanding and Implementing CORS & CSRF

Spread the love What is security? The world has become more

bluethinkinc Blogs