KEMBAR78
A presentationon SPRING-BOOT and CRUD operation | PDF
Introduction to
Spring-Boot with CRUD
Operations
Building a Simple RESTful API
Abhijite Deb Barman
Id : 2002029
1
Agenda
 What is Spring Boot ?
 It’s features
 What is CRUD ?
 Flow Architecture
 Setting Up a Spring Boot Project
 Creating Packages
 Implementing CRUD modules
 Testing CRUD Operations
Q & A Session
 Conclusion
2
Introduction of Spring Boot
• Spring Boot is an open-source Java-based framework for building
standalone, production-grade Spring applications.
Original Author: Rod Johnson
Developer: VMware
Initial Release: April 2014
Stable Release: 3.2.5(18 April 2024)
Written in: JAVA
Platform: JAVA Enterprise Edition
3
Features
4
Features
• Dependency Injection
-Dependency( external library ) injection in Spring Boot simplifies codes by
handling the management and provision of the necessary components.
• MVC(Model View Controller)
-Model : It's responsible for managing the application's data, including tasks like
retrieving data from a database, processing it, and updating it.
-View: The View receives data from the Model and displays it in a user-friendly
format.
-Controller: The Controller acts as an intermediary between the Model and the
View.
5
Features
• Auto-configuration:
• -It refers to the automatic setup of application components and
infrastructure based on the dependencies and configuration present
in the project
• Spring Security
• - Spring Security is a powerful authentication and authorization
framework for securing Java applications, particularly those built
using the Spring
6
Benefits of Using Spring Boot
• Efficiency: Minimizes boilerplate code and configuration.
• Rapid Development: Quickly prototype and develop applications.
• Convention Over Configuration: Reduces manual setup and
configuration.
• Production-Ready: Includes features for monitoring, security, and
more.
• Community and Support: Active community and extensive
documentation.
7
CRUD
• CRUD stands for Create, Read, Update, and Delete. It represents the
basic operations that can be performed on data in a database.
• Key Points:
• Create: Adding new records to the database.
• Read: Retrieving existing records from the database.
• Update: Modifying existing records in the database.
• Delete: Removing records from the database.
8
Architecture
9
Responsibility of Controller
10
 Receive incoming HTTP requests from clients.
 Process requests by invoking appropriate business logic.
 Return HTTP responses, typically in the form of JSON, XML, or
HTML, depending on the client's request.
Responsibility of Service
11
.
Implement and encapsulate business rules and logic.
Control transaction boundaries for operations that involve multiple
database interactions.
 Convert data between different formats or representations as required
by the application.
Responsibility of Model
12
 Define data entities.
 Encapsulate data and behavior.
 Define attributes and relationships.
 Implement validation logic.
 Create Data Transfer Objects (DTOs).
Spring initializr (www.start.spring.io)
13
Dependencies
• Dependency : A dependency refers to an external library or module that your
application relies on to provide certain functionality.
• 1.Spring Web(build applications using Spring MVC)
-module within the Spring Framework
-provides support for building web applications
• 2.Spring Data JPA (Persist data in SQL stores with java Persistence API using Spring
Data)
-provides a higher-level abstraction over JPA
-simplifying common data access tasks
14
Dependencies
• 3.Thymeleaf( Allows HTML to be correctly displayed in browsers and as static
prototypes)
-helps create the visual part of a web application
-insert dynamic data from the backend
• 4.MySql Driver(MySQL JDBC driver )
- Makes a connection between java app and MYSQL database)
• 5.Lombok(java annotation library which helps to reduce boilerplate)
- Lombok eliminates the need to write repetitive code
such as getters, setters, constructors etc.
15
Dependencies
• 6.Spring Boot Dev Tools
- provide fast application restarts, Live Reload, and configurations for
enhanced development experience
16
Demo Application
17
18
19
Database Connection
20
spring.application.name=demo
spring.datasource.url=jdbc:mysql://localhost:3306/formdatabse
spring.datasource.username=root
spring.datasource.password=abhijite
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
Create Four Packages under src/mian/java
21
22
Create class & interface under these packages
23
24
Model Package
25
 Create a Java class
 Annotated with @Entity
 Declare Table name
 Declare column with datatypes
 Declare Getter and Setter Method
 Set primary-key with @Id
 Set table name with @Table(name=“table_name”)
Model class
26
Repository Package
27
 Create an interface
 Annotated with @Repository
 Extends JpaRepository< , >
 Takes two Parameters
 Model Java class name and primary key datatype
Repository Interface
28
Service Package
29
 Create an interface
 Annotated with @Service
 Create abstract function
 Create a Java class
 Implements with service class
 Implements those abstract function
Service Interface
30
Service Class
31
Controller Package
32
 Create a Java class
 Annotated with @Controller
 Annotated by @Autowired with repository
 Marks a constructor, field, setter method, or config method as to
be autowired by Spring's dependency injection facilities.
33
34
35
36
37
Model class
38
READ
39
CREATE
40
41
42
CREATE
43
44
45
CREATE
46
47
48
CREATE
49
UPDATE
50
51
52
UPDATE
53
54
55
56
UPDATE
57
DELETE
58
58
59
60
61
Q & A Session
62
References
1. https://www.javatpoint.com/
2. https://spring.io/projects/spring-boot
3. https://www.w3schools.blog/spring-boot-tutorial
63
Resource
• Project : https://github.com/abhijite-bd/Springboot/
64
THANK YOU
65

A presentationon SPRING-BOOT and CRUD operation