Node.js(13)Node查询+添加数据到mongodb使用swaggerUI测试

1️⃣、查询数据

/**
 * @swagger
 * #接口地址,和app.js定义的接口一样app.use('wy',...)
 * /wy/getAllPlant:
 *   get:
 *      tags:
 *        - plant 嘎嘎项目
 *      summary: GET 查询嘎嘎项目的所有信息
 *      description: 传嘎嘎id , 进行查询   #描述
 *      parameters:     #参数
 *          - name: id
 *            in: query            #该参数在query里
 *            required: true       #是否必传
 *            description: 类型id
 *            type: integer   
 *      responses:
 *        "200":
 *           description: "200返回成功"                     
 *        "404":
 *           description: "【服务器有问题啦】"  
 * 
 */
const url = require("url");
router.get('/getAllPlant', function (req, res, next) {

    const { query } = url.parse(req.url, true)

    let id = query.id

    bill.find({ id: id }, function (err, docs) {
        if (err) {
            res.json({
                success: 'fail',
                data: null
            })
        } else {
            res.json({
                success: "suc",
                data: docs
            })
        }
    })
})

在这里插入图片描述

2️⃣、添加数据

/** 
 * @swagger
 * definitions:
 *      msg:
 *          type: "object"
 *          properties:
 *              id:
 *                  type: "integer"
 *                  format: "int32"
 *                  description: "用户ID"
 *              name:
 *                  type: "string"
 *                  description: "用户姓名"
 *              sex:
 *                  type: "integer"
 *                  format: "int32"
 *                  description: "性别:(1:男,2:女)"                     
 */

/**
 * @swagger
 * #接口地址,和app.js定义的接口一样app.use('wy',...)
 * /wy/insertInfo:
 *   post:
 *      tags:
 *        - plant 嘎嘎项目
 *      summary: POST 添加信息
 *      description: 添加一条用户信息
 *      requestBody:
 *            required: true
 *            content:
 *              application/json:
 *                  schema:
 *                      $ref: '#/definitions/msg' 
 *      responses:
 *        "200":
 *           description: "200返回成功"                  
 *        "304":
 *           description: "304成功" 
 *        "404":
 *           description: "【服务器有问题啦】"
 * 
 */
 
//内容代码见:Node.js学习(7)Node与MongoDB增删改查——插入数据
// https://blog.csdn.net/weixin_49567496/article/details/123132678

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值