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

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

Implementation of WireMock for better testing

Spread the love WireMock is a flexible and powerful tool

Magento 2: How to selected default option in configurable options?

Spread the love Configurable products in Magento 2 allow

How To Implement Simple JWT Authentication in Django Rest Framework

Spread the love We’ll learn how to use simple JWT

Optimizing Search: Integrating Elasticsearch in Django Applications

Spread the love What is Elasticsearch? Elasticsearch is a

How to create Customer Segments

Spread the love In Magento 2, “customer

Proxy Design Pattern and Requisition List in Magento 2

Spread the love Requisition List in Magento 2 Requisition

bluethinkinc Blogs