1、controller里面导入
router.post("/test", accountController.test);
2、声明test方法
let list = await model.test.findAll();
data = { status: 200, data: { list: list } };
return res.send(data);
3、创建test数据库和model里面的test.js
/**
* @author: metacamp
* @date: 2022-09-18 15:20:12
*/
"use strict";
var Sequelize = require("sequelize");
var sequelize = require("../config/db")
module.exports = sequelize.define('test', {
"id": {
"type": "INT",
"allowNull": true,
"defaultValue": null,
"primaryKey": true,
"autoIncrement": false,
"comment": "id"
},
"test": {
"type": "VARCHAR(100)",
"allowNull": true,
"defaultValue": null,
"primaryKey": false,
"autoIncrement": false,
"comment": "标题"
},
"age": {
"type": "INT",
"allowNull": true,
"defaultValue": null,
"primaryKey": false,
"autoIncrement": false,
"comment": "年龄"
},
"desc": {
"type": "VARCHAR(100)",
"allowNull": true,
"defaultValue": null,
"primaryKey": false,
"autoIncrement": false,
"comment": "标题"
},
}, {
freezeTableName: true,
timestamps: true,
createdAt: "createTime",
updatedAt: "updateTime",
});