const express = require("express");
const cors = require("cors");
const app = express();
app.use(cors());
const arring = [
{
userName:"zs",
sex:"男",
age:18,
className:"1班",
schoolNum:202201,
iphone:18888888888,
createTime:"20231204"
},
{
userName:"ls",
sex:"男",
age:19,
className:"2班",
schoolNum:202202,
iphone:18888888889,
createTime:"20231205"
}
];
// 新增接口
app.get("/add",(req,res)=>{
const dataAdd = req.query;
arring.push(dataAdd);
res.send("新增成功");
})
// 查询接口
app.get("/queryed",(req,res)=>{
const dataAdd = req.query;
if(!dataAdd.queryStr){
res.send(arring);
return;
}
for(var i=0;i<arring.length;i++){
for(var key in arring[i]){
if(arring[i][key]==dataAdd.queryStr){
res.send([arring[i]]);
}
}
}
console.log(222222222222);
})
app.listen(81,()=>{
console.log("express服务启动成功");
})
node.js新增接口
最新推荐文章于 2024-08-28 15:57:07 发布