- 对于 ORM,使用最多的 2 个库是 knexjs 和 sequelize,但是,我更喜欢 knex。
- 对于映射部分,据我所知,没有办法像在 c# 中那样做。通常我所做的是,在 app.js 中加载一个带有我的路由索引的文件。这是一个例子,
在你的 app.js 中
app.use('/', require('./backend/routes/index'))
然后,在您的路线/索引中
import express from 'express'
const router = express.Router()
// GET /
router.get('/', function (req, res) {
})
// GET /countries
router.get('/countries', (req, res, next) => {
})
// POST /subscribe
router.post('/subscribe', checkAuth, generalBodyValidation, (req, res, next) => {
})
// All routes to /admin are being solved in the backend/routes/admin/index file
router.use('/admin', require('./backend/routes/admin/index'))
module.exports = router
您的管理/索引文件可以是
从“快递”导入快递
const router = express.Router()
// POST /admin/login
router.post('/login', (req, res, next) => {
})
module.exports = router
这样,您将能够为您的路线提供更好的结构。
希望这能问到你的问题,如果它确实将我的答案标记为正确,如果不是,请告诉我你不明白的地方:D