Code Monkey home page Code Monkey logo

booking-hotel's Introduction

仿制booking.com 缤客

  • 仿制booking.com 我准备使用egg + vue + sequelize + mysql

创建后台数据库

  1. 先安装egg
    npm init egg --type=simple

  2. egg安装sequelize和mysql

详情可见:

  1. egg.js的使用
  • router 路由所在文件:

  • Controller Controller所在文件夹demo/app/controller/*。eggjs规定在controller中尽量只进行参数的转换、校验、返回值的转换等,复杂的业务操作应在Service中进行。Controller可以再次封装,比如使用BaseController继承eggjs的Controller,然后其它的controller继承BaseController即可,这点与Service不同,Service的父类只能是eggjs的Service。

  • Service Service所在文件夹为:demo/app/service/*,Service必须直接继承自eggjs的Service。

  • model 与数据库进行对接 ##安装 sequelize npm i sequelize -S npm i sequelize-cli -D 安装数据库依赖 npm i mysql2 sequelize init (.\node_modules.bin\sequelize init)

初始化完成之后生成的目录 config: 配置目录 migrations:迁移文件(数据库表结构) seeders: 种子文件(生成测试数据) models: 模型文件

创建数据库

sequelize:db create (.\node_modules.bin\sequelize db:create)

构建数据库的迁移结构

.\node_modules.bin\sequelize migration:create --name user // 创建一张user表

数据库结构

  • user: 用户表 用来存放用户的基本信息(用户名, 密码等) 其他表一样操作

数据库中创建表

  • .\node_modules.bin\sequelize db:migrate 生成表
  • .\node_modules.bin\sequelize db:migrate:undo:all 删除所有表

创建种子文件

  • seeders 文件夹下创建假数据
  • .\node_modules.bin\sequelize seed:generate --name user // 创建假数据文件

导入种子文件的数据

  • .\node_modules.bin\sequelize db:seed:all // 导入种子文件
  • .\node_modules.bin\sequelize db:seed:undo:all // 删除所有导入种子文件 ##egg改变的目录结构

├── Readme.md
├── app
│ ├── controller
│ │ ├──booking.js
│ │ └──user.js │ ├── model │ │ ├── currency.js
│ │ ├── hotelRent.js
│ │ ├── hotelStation.js │ │ ├── hotelType.js
│ │ ├── location.js │ │ └── user.js │ ├── public │ │ └──images
│ ├── service │ │ ├──booking.js │ │ └──user.js
│ └── router.js
├── config
│ ├── config.default.js │ └── tplugin.js
├── database
│ ├──migrations │ ├──seeders
│ └──config.json │ ├── .sequelizerc

前端页面的编写

vue + axios + stylus

booking-hotel's People

Contributors

xiaji1987 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.