当前位置: 首页 > news >正文

鞍山百度做网站营销策略分析

鞍山百度做网站,营销策略分析,怎么做网站信任,网站分为说明 上一篇: MVC实现之四这一篇主要介绍: 项目中用到的Sequelize库中的一些方法,参考使用Sequelize连接mysql将Model层加入Mar类中 Service层 还是从业务出发,Service层是调用方,调用方式和Controller层调用Service层一样 class Service {constructor(app) {const { model…说明 上一篇: MVC实现之四这一篇主要介绍: 项目中用到的Sequelize库中的一些方法,参考使用Sequelize连接mysql将Model层加入Mar类中 Service层 还是从业务出发,Service层是调用方,调用方式和Controller层调用Service层一样 class Service {constructor(app) {const { model } app;Service.prototype.model model;}async index() {const model Service.prototype.model;let data awati model.index();data.age 20;data.remarks forever 18;return data;} }Mar类 设计原则是,在不同层之间传递参数,通过Mar类.故需要在Mar类中挂载Model改写Mar类如下 class Mar {constructor(conf) {this.$app new koa(conf);this.$router new koaRouter();this.model new Model(this); // 这一行是新加的this.service new Service(this);this.controller new Controller(this);this.router new Router(this);}listen(port){ /* 未改变 */} }Model类 - 初始化 新建Mar类如下 class Mar {constructor ( app ) {console.log(Model ok);}test() {return Model for Service}async index() {return {name: marron}} }此时启动服务器,访问http://localhost:3000 Model类-操作数据库 准备数据库,按照docker-compose.yml构建容器.浏览器打开管理页面 注: 密码是example新建数据库 marron 准备就绪后,连接数据库,并测试 连接数据库 Sequelize库提供的接口如下 const sequelize new Sequelize(marron, root, example, {host: localhost,dialect: mysql }) sequelize.authenticate().then(() {console.log(Connect has been established successfully.);}).catch(err {console.error(Unable to connect to the database:, err);});写到Model类里面 进入Model类的时候,连接到数据库有一个testSQL方法用于测试,连接数据库是否成功 class Model {constructor(app) {this.connect();}connect(){this.sequelize new Sequelize(marron, root, example, {host: localhost,dialect: mysql})}testSQL() {this.sequelize.authenticate().then(() {console.log(Connect has been established successfully.);}).catch(err {console.error(Unable to connect to the database:, err);})} }看到这句话时,说明数据库连接成功了 表模型 sequelize提供的接口如下 const User sequelize.define(user, {// 属性firstName: {type: Sequelize.STRING,allowNull: false},lastName: {type: Sequelize.STRING},{// 参数} });加到Model层的addTableUser中 class Model{addTable {user: async () {const User this.sequelize.define(user, {// 属性name: {type: Sequelize.STRING,allowNull: false},date: {type: Sequelize.DATE,defaultValue: Sequelize.NOW}});// 同步到数据库User.sync({ force: true })}} }然后在Model的构造函数中调用一次 class Mode {constructor(app) {this.addTable.user();} }插入一条数据到表中 首先要有User表的结构暂时写在Model类的User方法中 class Model () {constructor(app) {}User() {return this.sequelize.define(user, {// 属性name: {type: Sequelize.STRING,allowNull: false},date: {type: Sequelize.DATE,defaultValue: Sequelize.NOW}})} }写添加user的方法写在add属性下面 class Model () {add {user: async (person) {const User this.User();User.create(person);// 同步新增用户this.sequelize.sync();}} }然后在constructor里面运行一次this.add.user({name:marron}) 查询数据 class Model {find {user: async () {const User this.User();return await User.findAll();}} }给Service提供服务 前面完成了连接数据库、创建表、往表内插入数据、查询数据的接口下面就是在Model中写一个index方法,给Service层中let data awati model.index(); 提供服务 class Model () {async index() {return await this.find.user();} }总代码如下 const koa require(koa); const koaRouter require(koa-router);class Mar {constructor(conf) {this.$app new koa(conf); // 相当于koa的实例this.$router new koaRouter(); // 相当于koa-router的实例this.model new Model(this);this.service new Service(this);this.controller new Controller(this);this.router new Router(this);}listen(port) {this.$app.listen(port, async () {console.log([mar]Server is running at http://localhost:${port});})} }class Router {constructor(app) {const { controller, $router, $app } app;$router.get(/, controller.index);$app.use($router.routes());} } class Controller {constructor(app) {const { service } app;console.log(Controller:, service.test());Controller.prototype.service service;}test() {return Controller for Router}async index(ctx) {const service Controller.prototype.service;ctx.body await service.index();} } class Service {constructor(app) {const { model } app;Service.prototype.model model;}test() {return Service for Controller}async index() {const model Service.prototype.model;let data await model.index();data.age 20;data.remarks forever 18;return data;} }const Sequelize require(sequelize);class Model {constructor(app) {this.connect();}// 给其他层的测试函数test() {return Model for Service}// 连接数据库的函数connect() {this.sequelize new Sequelize(marron, root, example, {host: localhost,dialect: mysql})}// 测试是否连接成功testSQL() {this.sequelize.authenticate().then(() {console.log(Connect has been established successfully.);}).catch(err {console.error(Unable to connect to the database:, err);});}async index() {return await this.find.user()}addTable {user: async () {const User this.sequelize.define(user, {// 属性name: {type: Sequelize.STRING,allowNull: false,},date: {type: Sequelize.DATE,defaultValue: Sequelize.NOW}});User.sync({ force: true })}}User() {return this.sequelize.define(user, {// 属性name: {type: Sequelize.STRING,allowNull: false,},date: {type: Sequelize.DATE,defaultValue: Sequelize.NOW}});}add {user: async (person) {const User this.User();User.create(person);// 同步新增用户this.sequelize.sync();}}find {user: async () {const User this.User();return await User.findAll();}} }module.exports Mar;
http://www.zqtcl.cn/news/996814/

相关文章:

  • 1g做网站空间a3网站建设
  • 海络网站室内设计工作前景
  • 柳州旅游网站建设橱柜设计师培训
  • 做网站属于什么专业个人是否可以申请网址
  • 品牌网站建是啥网站点击率怎么建
  • 上海市质量工程建设管理协会网站网站开发制作公司排行
  • 网站空间租用多少钱怎么在外贸公司拿订单
  • 建设银行网站背景图片温州做网站哪家比较好
  • 网站架设建设如何做网站电话
  • 团购网站怎么推广app平台搭建步骤
  • 沂水建设局网站郑州企业微网站建设
  • 免费企业网站空间wordpress目录主题
  • 做网站的销售话术苏州网站设计哪家公司好
  • 足球梦网站建设的基本思路网站介绍词
  • 森马网站建设情况网站推广中应注意哪些事项
  • 简单网站vs2008不能新建网站
  • 牌具做网站可以吗海外广告投放公司
  • 响应式单页网站模板宁波企业自助建站
  • 网站广告收费标准装饰设计公司起名
  • 网站开发人员构成中国兰州网官网
  • 网站设计的提案旅游网站建设风格
  • 成都网站建设的公司做高大上分析的网站
  • 专业企业网站建设公司成都的网站
  • 广东省建设教育协会官方网站首页怎么设置wordpress头像
  • 图书网站建设论文页游中心
  • 建网站的流程及注意事项任务网站建设
  • 河北邯郸做网站的公司哪家好辽源市住房和城乡建设局网站
  • 网站系统建设技术服务费安康市网站建设
  • 网络运行管理系统seo关键词优化方法
  • 西安学校网站建设价格徐州网页关键词优化