Crud Operation Using REST & Spring Boot
Crud Operation Using REST & Spring Boot
* Development Process
1. Set up Database Dev Enivironment
2. Create Spring boot Project using Spring initializr
3. Get list of employee
4 Get list of employee by ID
5.Add a new employee
6 Update an existing employee
* Application Architecture
............................................................
1. Spring boot will automatically configure your data source for you
2. based on entire from Maven Pom file
1.1 JDBC Driver: mysql-connector -java
1.2 spring Data(ORM) : spring-boot-starter-data-jpa
1.3 DB connection info from application.properties
-** application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/emloyee_directory?useSSL=
false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=Sanjay1996@
..................//..................
//what is JPA
JAVA Persistence API
1. Standard API for Object-to-Relational-Mapping(ORM)
2. only a Specification
3.defines a set of interface
4. Required an implementationto be usable
..................//..............
................//..............
................//............
* DAO Interface
public List<Employee>findAll();
}
..............//.............
@Repository
public class EmployeeDAOHibernateImpl implements EmployeeDAO{
@Autowired
public EmployeeDAOHibernateImpl (EntityManager theEntityManager){
entityManager - theEntityManager;
}
}
.....................//..................
* Developemet Process
...............................//............................
GET /api/employees/{employeeId}
REST -------------------------------------> Employee
client<-----------------------------------REST Controller
................//...............
POST /api/employees/
fistname,lastname,email
REST -------------------------------------> Employee
client<-----------------------------------REST Controller
...................//...................
PUT /api/employees/
REST -------------------------------------> Employee
client<-----------------------------------REST Controller
..........................//....................
DELETE /api/employees/{employeeId}
REST -------------------------------------> Employee
client<-----------------------------------REST Controller
...........................//..................