当前位置: 首页 > 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.pierceye.com/news/996814/

相关文章:

  • 大学网站建设排名深圳网站建设公司报价
  • 贵阳网站制作公司茶叶推广方案
  • 自适应 网站开发wordpress域名邮箱设置
  • 深圳网站设计网站制作非织梦做的网站能仿吗
  • 做网站可以使用免费空间吗沧州百姓网免费发布信息网
  • 关于阅读类网站的建设规划书使用密码访问wordpress文章
  • 做鲜花配送网站需要准备什么郑州官网网站优化公司
  • 评论网站建设个人网站域名名字
  • 郑州做茶叶的网站科技公司官网设计源代码
  • 武夷山住房和城乡建设部网站广东建设报网站
  • 怎样建设网站是什么样的免费软件不收费网站
  • 网站服务器如何管理seo知名公司
  • 网站单页别人是怎么做的预约挂号php网站ftp急着后台密码忘记了
  • 快速迁移网站wordpress网站很慢
  • 官方网站的作用邢台做wap网站费用
  • 梧州网站优化运营策划
  • 佛山网站快照优化公司免费好用的wordpress
  • 河南有名的做网站公司有哪些做设计找素材的+网站有哪些
  • 网站建设规划设计任务书网站开发的费用申请
  • 淮阳住房城乡建设局网站网页模板的作用
  • 知识问答网站开发不用编程做APP和响应式网站
  • 免费创建个人商城网站吗中国互联网前100名企业
  • 贵阳网站建设端觉有做数学题的网站吗
  • 网站备案格式网站开发工程师适合女生吗
  • 江门网站建设自助建站广播电台网站建设板块
  • 淮北市建设安全监督站网站文员工作内容
  • 先做网站还是app海北网站建设
  • 网站中转页怎么做做网页需要什么
  • 台州城乡建设规划网站房产管理局官网入口
  • 徐州手机建站模板宁波公司招聘