一、前置条件
前端:spring-boot(搭建方式参考:链接)
后端:linux、mongodb(可视化工具:Robo 3T,搭建方式参考:link)
测试url: localhost:8080/user
二、postman 使用方法示例
userId 字段的值随机获取,createTime字段的值是当前系统时间。

body设置

1
2
3
4
5
6
| {
"userId": "{{generated_userId}}",
"name": "com3",
"age": 20,
"creatTime": "{{current_timestamp}}"
}
|
Pre-request Script设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| function generateObjectId() {
const timestamp = Math.floor(new Date().getTime() / 1000).toString(16);
const machineIdentifier = '0aa495'; // 3字节机器标识符的示例
const processId = '9555'; // 2字节进程ID的示例
const counter = Math.floor(Math.random() * 0xFFFFFF).toString(16).padStart(6, '0'); // 3字节计数器
return timestamp + machineIdentifier + processId + counter;
}
// 将生成的 ObjectId 存储到环境变量
pm.environment.set("generated_userId", generateObjectId());
// 获取当前时间
const currentTimestamp = new Date().toISOString();
pm.environment.set("current_timestamp", currentTimestamp);
|
2.get 方法

3.delete 方法
删掉userId为"666d55670aa4959555d6b703" 的数据

再次使用get方法查看该条数据是否还存在
