This is the example project that shows you how to build Spring boot REST API that connects to MySQL databse using Spring JdcbTemplate.
- Create employee
- List all employees
- Fetch single employee by id
- Update employee by id
- Delete employee by id
We will create a Employee REST API, following are the rest end points
GET /api/v1/employees
[
{
"id": 1,
"name": "Bushan",
"location": "India",
"department": "IT"
},
{
"id": 2,
"name": "Bharath",
"location": "India",
"department": "Sales"
},
{
"id": 3,
"name": "Chaitra",
"location": "India",
"department": "IT"
}
]
GET /api/v1/employees/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of employee to fetch |
{
"id": 2,
"name": "Bharath",
"location": "India",
"department": "Sales"
}
POST /api/v1/employees
Parameter | Type | Description |
---|---|---|
employee reference |
Employee |
Required. Request body of employee |
{
"name": "Bharath",
"location": "India",
"department": "Sales"
}
PUT /api/v1/employees/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of employee to update |
employee reference |
Employee |
Required. Request body of employee |
{
"name": "Bharath",
"location": "India",
"department": "Sales"
}
DELETE /api/v1/employees/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of employee to delete |
Download the project and import it to any IDE.
Open the class SpringbootjdbcApplication.java
and run as Java application.
Insert gif or link to demo
Here are some related projects