一、环境准备
- 安装对应的插件 egg-mysql
npm i --save egg-mysql
- 在 config/plugin.js 开启插件
'use strict';
/** @type Egg.EggPlugin */
// 启用访问mysql数据库
exports.mysql = {
enable: true,
package: 'egg-mysql',
};
- 在config/config.default.js中添加mysql配置
- 添加相应路由
- 添加控制器
- 添加service
7.最终效果:
二、总结
整体来说,egg.js上手真的很简单,具体学习资料直接看官方文档就行,也写的非常详细,如果有需要沟通交流学习得请联系1798274010@qq.com