diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/.keep" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/demo1.js" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/demo1.js" new file mode 100644 index 0000000000000000000000000000000000000000..8cd7bf2dcbe3833cc8a8e2ab2cbc9ba15c3b8ff0 --- /dev/null +++ "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/demo1.js" @@ -0,0 +1,37 @@ +//## 课堂比较看懂,搭建一个web服务器,针对不同的参数,给予不同的回应,把html文件用异步方式去读取,返回.再去试下用orm框架去操作数据给不同参数返回不同的数据. + +var http = require('http'); +let fs = require("fs"); +let mysql = require("mysql2"); + +var server = http.createServer(function (request, response) { + console.log(request.method + ': ' + request.url); + + response.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'}); + + + if(request.url.indexOf("/food")>-1){ + let arrs = request.url.split("="); + let value=arrs[1]; + console.log("取到的值为"+value); + if(value=="noodles"){ + let noodles = fs.readFileSync("./html/noodles.html"); + response.end(noodles); + } + if(value=="kfc"){ + let kfc = fs.readFileSync("./html/kfc.html"); + response.end(kfc) + } + if(value=="McDonald"){ + let McDonald = fs.readFileSync("./html/McDonald.html"); + response.end(McDonald) + } + } + + response.end('

学好js,前端后端都能干

'); +}); + + +server.listen(8080); + +console.log('Server is running at http://127.0.0.1:8080/'); \ No newline at end of file diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/.keep" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/McDonald.html" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/McDonald.html" new file mode 100644 index 0000000000000000000000000000000000000000..3a77601a4505f3b1b2abbb351f9b35f07b0ffe8c --- /dev/null +++ "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/McDonald.html" @@ -0,0 +1,13 @@ + + + + + + + McDonald + + +

McDonald

+
不如KFC
+ + diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/kfc.html" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/kfc.html" new file mode 100644 index 0000000000000000000000000000000000000000..07078b9c0f49127191e40a8103a865e36c16e29e --- /dev/null +++ "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/kfc.html" @@ -0,0 +1,13 @@ + + + + + + + KFC + + +

KFC

+
不如麦当劳
+ + diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/noodles.html" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/noodles.html" new file mode 100644 index 0000000000000000000000000000000000000000..c2079cbfbed072cf8fbebe3737138d09487b5842 --- /dev/null +++ "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/http/html/noodles.html" @@ -0,0 +1,13 @@ + + + + + + + 兰州拉面 + + +

兰州拉面

+
报吃
+ + diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/.keep" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/config.js" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/config.js" new file mode 100644 index 0000000000000000000000000000000000000000..e9dd6fddd68dd2a5ac9c0f20d9b99fe5b7093637 --- /dev/null +++ "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/config.js" @@ -0,0 +1,8 @@ +let database = { + host: "localhost", + user: "root", + password: "root", + port: 3306, + database: 'user' +} +module.exports = database diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/demo1.js" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/demo1.js" new file mode 100644 index 0000000000000000000000000000000000000000..e6d3d6b866f69d09b0c6de1accc9ae384b3dc655 --- /dev/null +++ "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/demo1.js" @@ -0,0 +1,31 @@ +//### 作业:第一个能不能使用promise的异步函数,封装下数据库的查询,二 把sequelize 配置完成,至少能查询一个表去看看sequelize的文档,实现curd + + + +let mysql=require("mysql2"); +let conn=mysql.createConnection({ host:"localhost", user: "root", password: "root", port: "3306", database: "user"}) +conn.commit(); + + +async function useasync(){ + let data=await use(); + // console.log(data); +} + +function use(){ + return new Promise((resolve,rejects)=>{ + let select="select*from student "; + conn.query(select,(err,data)=>{ + console.log(err); + console.log(data); + if(err!=null){ + rejects(err); + }else{ + resolve(data); + } + }) + }) +} +useasync(); +conn.end(); + diff --git "a/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/demo2.js" "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/demo2.js" new file mode 100644 index 0000000000000000000000000000000000000000..ea8979c8afb2eb398bf4052dfa71f8d4156b5a98 --- /dev/null +++ "b/\346\234\261\347\253\240\345\275\254/\344\275\234\344\270\232/orm/demo2.js" @@ -0,0 +1,76 @@ +// ### 作业:创建一个学生表,里面有班级字段,里面最好有自己班上同学姓名,其它班级的姓名随机写,有个字段存储游戏的分值,先实现随机的数值写入,查询出各班级前三名的学生 + +let config=require("./config"); +const { Sequelize , Model,DataTypes}=require("sequelize"); +let host =config.host; +const sequelize = new Sequelize(config.database, config.user, config.password, { + //申明下使用的数据库 + dialect: 'mysql', + host:config.host, + port: config.port, + logging: true, + timezone: '+08:00', + define: { + timestamps: false, + + } +}); +sequelize.sync({force:false}) +class user extends Model{} +user.init({ + id:{ + type:DataTypes.INTEGER, + allowNull:false, + primaryKey: true, + autoIncrement:true + }, + name:{ + type: DataTypes.STRING + }, + class:{ + type: DataTypes.INTEGER + }, + score:{ + type: DataTypes.INTEGER + } + +},{ + sequelize, + modelName:'user', + tableName:'user', +}); +user.findAll().then(name =>{ + //console.log(JSON.stringify(name,null,2)); +}) + + +// setTimeout(function(){ + +// let user=user.build({name:'msk',class:6,score:60}); +// user.save(); + +// },1000); +function add(){ + + let auser=user.build({name:'cxy',class:'6',score:Math.floor(Math.random() * 101)}); + let auser2=user.build({name:'lsz',class:'7',score:Math.floor(Math.random() * 101)}); + let auser3=user.build({name:'zzb',class:'7',score:Math.floor(Math.random() * 101)}); + auser.save(); + auser2.save(); + auser3.save(); +}; + +// for(i=1;i<=5;i++){ +// add(); +// } +user.findAll({ + where: { + class:7, + }, + limit:3, + order:[ + ["score", "DESC"] + ] +}).then(users => { + console.log("正确的输入:", JSON.stringify(users, null, 4)); +}); \ No newline at end of file