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

Understanding Database Allows Callout in Salesforce Apex

Spread the love In Salesforce, the Database.AllowsCallouts

PODMAN

Spread the love 1.Introduction Podman: The Modern Container

Running Your Java Program (JAR) 24/7 on AWS EC2 Automatically

Spread the love Introduction Running a Java application

Building a REST API with Spring Boot

Spread the love Introduction REST (Representational State

Custom API to Fetch Customer Data by Customer ID in Spryker

Spread the love Introduction In this blog post, we will

Creating a Custom Module for a Custom Frontend Page in Spryker

Spread the love To create a custom module for a custom

How to create custom module api get category list without access token in Spryker

Spread the love To create a custom API for fetching a

Creating a Custom Glue API in Spryker

Spread the love Spryker’s Glue API is a powerful tool

Get AI Generated 360-Degree View of Account Summary in Dynamics 365 Sales

Spread the love Navigating the demanding landscape of sales

Enhancing Productivity with Dynamics 365: The Power of Session Restore

Spread the love Enhancing Productivity with Dynamics 365:

bluethinkinc Blogs