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

Enhancing Productivity with Dynamics 365: The Power of Session Restore

Spread the love Enhancing Productivity with Dynamics 365:

Salesforce Admin

Spread the love In our last blog, we discussed common

Unlocking AI with Spring Boot: Real-World Use Cases and Solutions

Spread the love Artificial Intelligence (AI) has moved from

Enhancing Performance with Reactive Java: A Beginner-Friendly Guide

Spread the love In today’s fast-paced software

Integrating Azure Function with Dynamics 365

Spread the love Signup on azure portal and make sure to

How to Create a Power Apps Component Framework (PCF) with React

Spread the love If youʼve been looking to supercharge your

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

bluethinkinc Blogs