Spring Boot H2 简明教程

Spring Boot & H2 - REST APIs

与上一章 Application Setup 一样,我们在 Spring Boot 项目中创建了所需文件。现在在 POSTMAN 中创建以下集合来测试 REST API。

As in previous chapter Application Setup, we’ve created the required files in spring boot project. Now create the following collection in POSTMAN to test the REST APIs.

postman structure
  1. GET Get All Employees − A GET request to return all the employees.

  2. POST Add an Employee − A POST request to create an employee.

  3. PUT Update an Employee − A PUT request to update an existing employee.

  4. GET An Employee − A GET request to get an employee identified by its id.

  5. Delete An Employee − A Delete request to delete an employee identified by its id.

GET All Employees

在 POSTMAN 中设置以下参数。

Set the following parameters in POSTMAN.

  1. HTTP Method − GET

  2. URL − http://localhost:8080/emp/employees

Add an Employee

在 POSTMAN 中设置以下参数。

Set the following parameters in POSTMAN.

  1. HTTP Method − POST

  2. URL − http://localhost:8080/emp/employee

  3. BODY − An employee JSON

{
   "id": "1",
   "age": "35",
   "name": "Julie",
   "email": "julie@gmail.com"
}

Update an Employee

在 POSTMAN 中设置以下参数。

Set the following parameters in POSTMAN.

  1. HTTP Method − PUT

  2. URL − http://localhost:8080/emp/employee

  3. BODY − An employee JSON

{
   "id": "1",
   "age": "35",
   "name": "Julie",
   "email": "julie.roberts@gmail.com"
}

GET An Employees

在 POSTMAN 中设置以下参数。

Set the following parameters in POSTMAN.

  1. HTTP Method − GET

  2. URL - http://localhost:8080/emp/employee/1 − Where 1 is the employee id

Delete An Employees

在 POSTMAN 中设置以下参数。

Set the following parameters in POSTMAN.

  1. HTTP Method − DELETE

  2. URL - http://localhost:8080/emp/employee/1 − Where 1 is the employee id