后台搭建操作流程
后台搭建操作流程
环境准备
1.node。下载
2. mysql。下载
3. 远程连接ssh 客户端termius。下载
4. redis
- 下载地址
- 客户端下载地址:链接。提取码:2zho
项目准备
1.新建项目文件夹 mkdir test。cd test
5. 修改全局的npm命令为cnpm。npm i -g cnpm。(过程有点慢,大概5分钟)
6. 安装 skyjt
7. 初始化项目 jt init -f (有点慢)
8. 创建项目 如 test 。cd test
9. cnpm i
10.nodemon index.js
12.config中配置数据库、redis。
开发阶段
api创建
module.exports = {
__swagger__: {
name: 'helloworld',
description: ''
},
add: { // 接口函数名
name: '增加', // 接口名称
desc: '接口开始', //接口介绍
method: 'all', // 可 get/post
controller: 'test/test.add',// 具体实现的方法路径
param: { // 参数对象
name:{ // 参数命名
name: '名字',
desc: '用户名',
type: 'string',
req: 0
}
},
token: false,
needSign: false,
err_code: {},
test: {},
front: true
}
}
方法实现
// 插入数据
async add (ctx) { // ctx 全局对象
let name = ctx.checkedData.data //参数对象
const data = await global.db.t1.C(name).run()
ctx.ok(data)
},
// 删除
async del (ctx) {
let id = ctx.checkedData.data
const data = await global.db.t1.D(id).run()
ctx.ok(data)
},
// 更新
async change (ctx) {
const data = await global.db.t1.U({id:2},{name:"xueyan"}).run()
ctx.ok(data)
},
// 查询
async query (ctx) {
const data = await global.db.t1.R().run()
ctx.ok(data)
}