diff --git "a/\346\236\227\351\221\253/2022.03.24/app.js" "b/\346\236\227\351\221\253/2022.03.24/app.js" index a8e0f3731f734e74b65e11396cb6d64aab371294..d2a4661beacd30e2d558920111d679a45ad6825c 100644 --- "a/\346\236\227\351\221\253/2022.03.24/app.js" +++ "b/\346\236\227\351\221\253/2022.03.24/app.js" @@ -1,56 +1,3 @@ -/** -//////////////////////////////////////////////////////////////////// -// _ooOoo_ // -// o8888888o // -// 88" . "88 // -// (| ^_^ |) // -// O\ = /O // -// ____/`---'\____ // -// .' \\| |// `. // -// / \\||| : |||// \ // -// / _||||| -:- |||||- \ // -// | | \\\ - /// | | // -// | \_| ''\---/'' | | // -// \ .-\__ `-` ___/-. / // -// ___`. .' /--.--\ `. . ___ // -// ."" '< `.___\_<|>_/___.' >'"". // -// | | : `- \`.;`\ _ /`;.`/ - ` : | | // -// \ \ `-. \_ __\ /__ _/ .-` / / // -// ========`-.____`-.___\_____/___.-`____.-'======== // -// `=---=' // -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // -// 佛祖保佑 永不宕机 永无BUG // -//////////////////////////////////////////////////////////////////// - * - * - * - * 什么是动态资源:相对静态资源(图片,css,js前端文件,) 需要访问数据库(redis mysql......). - * - * url 的资源定位:我们简单把 /home/css/demo.css 我们认为这种就是 静态资源, - * - * 动态资源: ?a=index&c=index a 表示 action ,c 表示 controller - * - * - * http://localhost:8080/demo.html?a=index&c=index - * - * url: http://localhost:8080/demo.html?a=index&c=index - * - * uri:demo.html?a=index&c=index - * - * path:demo.html (这个path 也是开发者自己定义的,这种格式没限定 demo.html(写成 .html 为了seo ) - * 也可以写 demo 也可以 demo.htm) - * - * query: a=index&c=index 就可以理解为服务端传递参数用的,数据进行查找 - * - * - * - * - * - * - */ - - - let http = require("http"); @@ -66,101 +13,80 @@ server.listen(8080); server.on('request', function (req, res) { - /** - * 流方式获取数据 - */ let postData = ''; - req.on('data', function (chunk) {//流方式读取数据,数据一段一段传输,这一段代码是异步的 + req.on('data', function (chunk) { postData += chunk; }); - req.on('end', async function () {//表示流已经接受完毕 + req.on('end', async function () { console.log("流方式获取数据:::::"); - console.log(postData);//可以获取到数据??why? + console.log(postData); - /** - * 拆分post数据 - */ - let postArr = postData.split("&");// ['name=demo','password=23']; + let postArr = postData.split("&"); let postVals = []; for (let ky in postArr) { let val = postArr[ky];//'a=index'....... let temPostArray = val.split("="); postVals[temPostArray[0]] = temPostArray[1]; } - //给 req 对象添加一个 query + req.post = postVals; let url = req.url; - //静态资源与动态资源判断 - //在web服务器,要尽量使用异步函数 - //web服务器给谁用的,给用户,给管理员用 - //node自身的问题,node 是单线程的. - //404 页面 + if (url.lastIndexOf('.') > -1) { console.log(url); let path = '.' + url; readFileByPromise(path, res); } else { - req.cookie={};//初始化cookie的值 - //取出cookie,把cookie转成 key=val 的数组 + req.cookie={}; if (req.headers.cookie) { let cookieStrArr = req.headers.cookie.split("; "); - let cookies = {};//还是以json格式来存储 + let cookies = {}; cookieStrArr.forEach(element => { let cookieKeyAndVal = element.split("="); cookies[cookieKeyAndVal[0]] = cookieKeyAndVal[1]; }); - // console.log('session获取到的数据'); - // console.log(cookies['demo']); - // console.log(session[cookies['demo']]); - req.cookie = cookies;//保存到请求对象 + + req.cookie = cookies; } - //console.log(req.cookie); - //每次请求给他生成一个唯一的cookie建 - //cookie名称我们就取 node_session,我们的目标是啥?生成以后在会话期就不再设置 - //在判断里面一个字符串 是true还是false???????它是true,'0' 你们去验证下 + let node_session=null; - if (!req.cookie.node_session) {//没有node_session设置一个 + if (!req.cookie.node_session) { node_session = (new Date().getTime() + "_" + Math.random()); res.setHeader('Set-Cookie', "node_session=" + node_session); req.cookie.node_session = node_session; - } else {//有node_session + } else { node_session = req.cookie.node_session; } res.setHeader("Content-type", "text/html;charset=utf8"); - //根据cookie去读取session的值 if (session[node_session]) { console.log('session data'); console.log(session); req.session = session[node_session]; } - //去除query,使用split 以 demo?a=index&c=index 为例 let queryString = url.split("?")[1];//a=index&c=index - let queryArr = queryString.split("&");// ['a=index','c=index']; + let queryArr = queryString.split("&"); let keyVals = []; for (let key in queryArr) { - let vals = queryArr[key];//'a=index'....... + let vals = queryArr[key]; let temArray = vals.split("="); keyVals[temArray[0]] = temArray[1]; } - //给 req 对象添加一个 query req.query = keyVals; console.log(keyVals['c']); let controllerPath = './home/controller/' + keyVals['c'].replace(keyVals[0], keyVals['c'][0].toUpperCase()) + "Controller"; - //正常的项目.controller 是由多个的,model也是有多个的,所以通过url 可动态的调用 - let controller = require(controllerPath);//controller 就是一个 class - //console.log(keyVals['a']); - //keyVals['a'] 变量吧,所以在json 里面,要去调用它的key ,用 .方式 key必须是个常量, + let controller = require(controllerPath); + console.log(controller); let action = keyVals['a']; - let obj = new controller(req, res, nunjucks);//找控制器,然后执行控制器下的方法 - let content = await obj[action]();//我们业务逻辑 + let obj = new controller(req, res, nunjucks); + let content = await obj[action](); if (res.session) { session[node_session] = res.session; } @@ -171,11 +97,6 @@ server.on('request', function (req, res) { res.write(content); res.end(); } - // var date = new Date(); //获取到当前时间 - // date.setTime(date.getTime() + 30 * 60 * 10000);//毫秒 - //res.setHeader('Set-Cookie', "userInfo=987654321; expires="+date.toGMTString()+"; path=/mydir;"); - - // } }) @@ -207,17 +128,3 @@ async function readFileByPromise(fileName, res) { res.end(); } -/* - * h5 + css + vue + webapi 根本 - * - * - */ - - -/** - * 搭建个自己的网站,实现动态网页,与动态网页的渲染展示 - * - * 优化 数据库的查询(使用promise) + 去了解下 js的 class - * - * - */ \ No newline at end of file diff --git "a/\346\236\227\351\221\253/2022.03.24/config/db.js" "b/\346\236\227\351\221\253/2022.03.24/config/db.js" index e1b143475ee09e95e6de0637d7af3fac6d05c55e..71a47a5f33ef49a9aa4c0076abe7418bdc2d6ed8 100644 --- "a/\346\236\227\351\221\253/2022.03.24/config/db.js" +++ "b/\346\236\227\351\221\253/2022.03.24/config/db.js" @@ -9,10 +9,3 @@ let dbconfig = { } module.exports = dbconfig; -//dbconfig.key(); - -// json 非常重要!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -// 其实它很单纯,看到 { 开头 }结尾就是json ,它是 key val 形式 ,key 就是 类型数组的键名,value 是对应的值 - -// value 不限定类型 \ No newline at end of file diff --git "a/\346\236\227\351\221\253/2022.03.24/home/controller/BaseController.js" "b/\346\236\227\351\221\253/2022.03.24/home/controller/BaseController.js" index 66d265e4dbefd72703b5274ae8b6b275183c87ad..790b2131ae8d751c14d96a04fe3af3f169bc0148 100644 --- "a/\346\236\227\351\221\253/2022.03.24/home/controller/BaseController.js" +++ "b/\346\236\227\351\221\253/2022.03.24/home/controller/BaseController.js" @@ -6,7 +6,7 @@ class BaseController { this.req = req; this.res = res; this.nunjucks = nunjucks; - this.nunjucks.configure('./home/html', { autoescape: true });//配置模板的目录 + this.nunjucks.configure('./home/html', { autoescape: true }); } diff --git "a/\346\236\227\351\221\253/2022.03.24/home/controller/IndexController.js" "b/\346\236\227\351\221\253/2022.03.24/home/controller/IndexController.js" index 57d9af51225f4934757ba33f17176b678f6958aa..b8e030a38f2bfce2dbc83c4d1f1687ee0b9187d1 100644 --- "a/\346\236\227\351\221\253/2022.03.24/home/controller/IndexController.js" +++ "b/\346\236\227\351\221\253/2022.03.24/home/controller/IndexController.js" @@ -12,11 +12,7 @@ class IndexController extends BaseController { let sql = 'select * from number where date=?'; //console.log(res); try { - let result = await mysqlObj.query(sql, date);//等待数据的返回,但是线程可以干别的事情,线程我们就理解为饭店的服务员, - //node只能请得起一个服务员, await + promise 表示,这一段代码需要同步(服务员招待了客户, - //客户告诉服务器,我自己来,你忙别的) 如果说这块是阻塞的,那请求2次,5*2 =10 - //如果不是阻塞的 - //result 是啥类型?数组 + let result = await mysqlObj.query(sql, date); return this.display('index.html', { data: result,title:'我是index11111111' }) } catch (err) { console.log(err); @@ -28,15 +24,9 @@ class IndexController extends BaseController { let mysqlObj = new mysql(); let date = this.req.query['date']; - //console.log('date-----'+date); let sql = 'select * from number where date=?'; - //console.log(res); try { - let result = await mysqlObj.query(sql, date);//等待数据的返回,但是线程可以干别的事情,线程我们就理解为饭店的服务员, - //node只能请得起一个服务员, await + promise 表示,这一段代码需要同步(服务员招待了客户, - //客户告诉服务器,我自己来,你忙别的) 如果说这块是阻塞的,那请求2次,5*2 =10 - //如果不是阻塞的 - //result 是啥类型?数组 + let result = await mysqlObj.query(sql, date); return this.display('detail.html', { data: result }) } catch (err) { console.log(err); @@ -45,75 +35,8 @@ class IndexController extends BaseController { } - diji() { - - console.log("盖地基"); - - } - - zhuzi() { - - console.log("盖柱子"); - - } - - qizhuang() { - - console.log("砌砖"); - - } - - quchunishuijiang() { - console.log(this.nishuijiang); - - } - - } module.exports = IndexController; -// let obj = new IndexController('李四');//开始去搭积木,比方说我想搭建个小房子 ,new 就表示 具体要做个工程了 -// // 类是不限制构建次数 -// obj.diji(); -// obj.zhuzi(); -// obj.qizhuang(); -// obj.quchunishuijiang(); - -// let obj2 = new IndexController('张三');//我们每次项目对象正常我们目的是不一样的 -// //this就表示每次构建的这个对象 -// obj2.quchunishuijiang(); - -// console.log(obj==obj2) - - -/** - * 回顾 class java es6 - * - * 面向对象编程三大特点:继承,封装,多态(方法的重写) - * - * 封装: - * 继承:extends 需要继承 - * - * - * - * - * class 中文翻译过来 班级 在编程里面叫 类,我们就按班级理解 - * - * 班级里有很多成员,单元可以有一个,元素 在js 里面就是 函数(js class 里面不写function 就是函数名与 {} , - * - * 在class 里面就不叫函数了,就叫 方法),和属性() - * - * class 的使用 , new 加一个class 名称,我们可以理解为, class 就是一堆的积木,里面有 圆柱体,有长方体.....(就是方法),但是我们积木 - * - * 没有构建成具体的建筑. - * - * - * class :元素 - * 1 函数,不用function 去标识,而且在类里面不叫函数了,叫方法 - * 2 属性 就理解成变量,跟普通变量相对多个 this - * - * - * - */ diff --git "a/\346\236\227\351\221\253/2022.03.24/home/controller/UserController.js" "b/\346\236\227\351\221\253/2022.03.24/home/controller/UserController.js" index 85afc03bb61e95f7614a2031d5cea4020d0f0456..61cc9d694cc024ef147c0d40f98f18223ac3a7e4 100644 --- "a/\346\236\227\351\221\253/2022.03.24/home/controller/UserController.js" +++ "b/\346\236\227\351\221\253/2022.03.24/home/controller/UserController.js" @@ -7,7 +7,7 @@ const EncAndDec = require("../../untis/EecAndDec"); class UserController extends BaseController { async login() { - if(this.req.session){//表示已经登录 + if(this.req.session){ let userInfo = JSON.parse(this.req.session); return '301' }else{ @@ -15,32 +15,18 @@ class UserController extends BaseController { } } - - /** - * 前台用户注册页面 - * @returns - */ async userReg(){ - return this.display("userReg.html"); } - - /** - * - * @returns 用户注册后端逻辑 - */ async handleReg(){ - //又没判断用户是否为空? 也没有判断,密码是否为空 let name = this.req.post['name']; - let password =this.req.post['password']; //EncAndDec.md5(this.req.post['password']); + let password =this.req.post['password']; let sql = "select * from user where name=? and password=? limit 1"; let userModel = new UserModel(); let userList=await userModel.query(sql,[name,password]); - //console.log(userList); 数组转成 json的字符串,反过来怎么处理 - //写入到数据库 你们完善 TODO - //JSON.parse 把字符串还原成数组或者 json格式 + let userInfo={}; - if(userList.length>0){//长度大于0 说明查询到数据了,说明用户密码都是正确的 + if(userList.length>0){ userInfo = userList[0]; this.res.session = JSON.stringify(userInfo); } @@ -53,7 +39,7 @@ class UserController extends BaseController { try{ let userList = await user.select(); - return '我是用户列表页面'//就是把对象转成json格式 + return '我是用户列表页面' }catch(err){ console.log(err); diff --git "a/\346\236\227\351\221\253/2022.03.24/home/controller/index.js" "b/\346\236\227\351\221\253/2022.03.24/home/controller/index.js" index fb69ae86016b681a654ce9e296d5e5e183c54bbd..3ee32aa7150f2e218a7fee34a38f9f5027a8e776 100644 --- "a/\346\236\227\351\221\253/2022.03.24/home/controller/index.js" +++ "b/\346\236\227\351\221\253/2022.03.24/home/controller/index.js" @@ -1,7 +1,4 @@ -/** - * 在mvc 中,controller 是指挥者者,他指挥着数据获取与模板的渲染 - * - */ + let fs = require("fs"); let index={ @@ -12,10 +9,7 @@ let index={ //console.log('date-----'+date); let sql = 'select * from number where date=?'; //console.log(res); - let result= await mysql.query(sql,date,res);//等待数据的返回,但是线程可以干别的事情,线程我们就理解为饭店的服务员, - //node只能请得起一个服务员, await + promise 表示,这一段代码需要同步(服务员招待了客户, - //客户告诉服务器,我自己来,你忙别的) 如果说这块是阻塞的,那请求2次,5*2 =10 - //如果不是阻塞的 + let result= await mysql.query(sql,date,res); console.log(result); let html=''; @@ -44,12 +38,9 @@ let index={ let mysql = require("../../model/base"); let date = req.query['date']; //console.log('date-----'+date); - let sql = 'select * from number order by id desc limit 1 ';//取出最先的一条数据 + let sql = 'select * from number order by id desc limit 1 '; //console.log(res); - let result= await mysql.query(sql,date,res);//等待数据的返回,但是线程可以干别的事情,线程我们就理解为饭店的服务员, - //node只能请得起一个服务员, await + promise 表示,这一段代码需要同步(服务员招待了客户, - //客户告诉服务器,我自己来,你忙别的) 如果说这块是阻塞的,那请求2次,5*2 =10 - //如果不是阻塞的 + let result= await mysql.query(sql,date,res); console.log(result); let html=''; @@ -76,4 +67,3 @@ let index={ module.exports=index; -// \ No newline at end of file diff --git "a/\346\236\227\351\221\253/2022.03.24/model/Base.js" "b/\346\236\227\351\221\253/2022.03.24/model/Base.js" index 937befcfe89b8956fe17e0c8286574e16469edca..962923acf407c423592ec6deab7cda2ec892fadd 100644 --- "a/\346\236\227\351\221\253/2022.03.24/model/Base.js" +++ "b/\346\236\227\351\221\253/2022.03.24/model/Base.js" @@ -5,49 +5,27 @@ let mysqlModule = require("mysql"); let db = require("../config/db"); class mysql { - - /** - * 初始化 - */ constructor() { - } - query(sql, value) { - let promise = new Promise(function (resolve, reject) { let connection = mysqlModule.createConnection({ host: db.host, user: db.user, password: db.password, database: db.database }); - connection.connect(); - /** - * 推荐使用占位符方式查询,占位符可以防止 sql注入 占了 80%漏洞都是sql - */ connection.query(sql, value, function (err, result) { if (err) { reject(err.message) } else { - - //setTimeout(function () {//模拟数据的慢查询 resolve(result); - //},5000) - } connection.end(); }) - - }) return promise; - } - /** - * 简单的数据查询 - * @param {}} condtion - */ select() { let sql = "select * from " + this.table; diff --git "a/\346\236\227\351\221\253/2022.03.24/model/UserModel.js" "b/\346\236\227\351\221\253/2022.03.24/model/UserModel.js" index f5b5c67efca3f38c5003c5d62a44877509c04256..ad6439e095a24b3903c15d6af9181094470ca0e2 100644 --- "a/\346\236\227\351\221\253/2022.03.24/model/UserModel.js" +++ "b/\346\236\227\351\221\253/2022.03.24/model/UserModel.js" @@ -4,17 +4,11 @@ let Base = require("./Base"); class UserModel extends Base{ constructor(){ - super();//父亲构造器,意思说 父亲的构造器也要执行 + super(); this.table = 'user'; } - - - - - - } module.exports = UserModel; \ No newline at end of file diff --git "a/\346\236\227\351\221\253/2022.03.24/untis/EecAndDec.js" "b/\346\236\227\351\221\253/2022.03.24/untis/EecAndDec.js" index e5fa3450dbbb5c71ba545fbde06d99a9d31e8140..b2df44b74771240a2b77bed638d69f8c0b4ac6ea 100644 --- "a/\346\236\227\351\221\253/2022.03.24/untis/EecAndDec.js" +++ "b/\346\236\227\351\221\253/2022.03.24/untis/EecAndDec.js" @@ -4,11 +4,8 @@ let EncAndDec = { md5: function (data) { let md5 = crypto.createHash("md5"); - md5.update(data); - return md5.digest("hex"); - } } diff --git "a/\346\236\227\351\221\253/2022.03.25/ThinkNode.js" "b/\346\236\227\351\221\253/2022.03.25/ThinkNode.js" index 2dd5faf36847bb197ae79855ed38136a9c9f9ad8..82c04eeff2ce3292ff50b52cc6f78daf37ac0a94 100644 --- "a/\346\236\227\351\221\253/2022.03.25/ThinkNode.js" +++ "b/\346\236\227\351\221\253/2022.03.25/ThinkNode.js" @@ -16,7 +16,6 @@ let ThinkNode = { port: dbCofig.port }) connection.createConnection(); - //查询所以的表 let tables = 'show tables' connection.query(tables, function (err, result) { if (err) { @@ -44,7 +43,6 @@ let ThinkNode = { findControllAndHandle: async function (req, res, funcend,session) { let url = req.url; let isStatic = false; - //静态资源 staticFileType.forEach(element => { if (url.lastIndexOf(element) > -1) { isStatic = true; diff --git "a/\346\236\227\351\221\253/2022.03.25/config/db.js" "b/\346\236\227\351\221\253/2022.03.25/config/db.js" index e1b143475ee09e95e6de0637d7af3fac6d05c55e..90011186d9fb30d134c3135edb9176a8389d72ca 100644 --- "a/\346\236\227\351\221\253/2022.03.25/config/db.js" +++ "b/\346\236\227\351\221\253/2022.03.25/config/db.js" @@ -8,11 +8,3 @@ let dbconfig = { } module.exports = dbconfig; - -//dbconfig.key(); - -// json 非常重要!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -// 其实它很单纯,看到 { 开头 }结尾就是json ,它是 key val 形式 ,key 就是 类型数组的键名,value 是对应的值 - -// value 不限定类型 \ No newline at end of file diff --git "a/\346\236\227\351\221\253/2022.03.25/expressdemo.js" "b/\346\236\227\351\221\253/2022.03.25/expressdemo.js" index 9dd1648016fe1c00b14d6e2502260828483c5775..1bc0d24476e54f5f3e3abc6bac089b7ce52a81b4 100644 --- "a/\346\236\227\351\221\253/2022.03.25/expressdemo.js" +++ "b/\346\236\227\351\221\253/2022.03.25/expressdemo.js" @@ -15,14 +15,10 @@ function app(){ res.end(); } - /** - * use方法就是把函数添加到函数数组中---前置控制器 - * @param task - */ app.get = function (url,task) { urls[url]=task; } - return app; // 返回实例 + return app; } let a= app(); diff --git "a/\346\236\227\351\221\253/2022.03.25/home/controller/UserController.js" "b/\346\236\227\351\221\253/2022.03.25/home/controller/UserController.js" index ecc6e85a7d84e15b6c06c0e8b9bbd45a03561d05..cde2f096cece3ea06e6385f2d8d6915d1f561b0f 100644 --- "a/\346\236\227\351\221\253/2022.03.25/home/controller/UserController.js" +++ "b/\346\236\227\351\221\253/2022.03.25/home/controller/UserController.js" @@ -28,10 +28,6 @@ class UserController extends BaseController { return await user.update({name:'admin2'},{id:3}); } - /** - * 前台用户注册页面 - * @returns - */ async userReg(){ return this.display("userReg.html"); } @@ -48,7 +44,7 @@ class UserController extends BaseController { try{ let userList = await user.find({name:'demo',password:'123456'}); - return JSON.stringify(userList);//就是把对象转成json格式 + return JSON.stringify(userList); }catch(err){ console.log(err); diff --git "a/\346\236\227\351\221\253/2022.03.25/model/UserModel.js" "b/\346\236\227\351\221\253/2022.03.25/model/UserModel.js" index 94211aaa67762fddc3bda3487f84194e01a2b8a1..ad6439e095a24b3903c15d6af9181094470ca0e2 100644 --- "a/\346\236\227\351\221\253/2022.03.25/model/UserModel.js" +++ "b/\346\236\227\351\221\253/2022.03.25/model/UserModel.js" @@ -9,12 +9,6 @@ class UserModel extends Base{ } - - - - - - } module.exports = UserModel; \ No newline at end of file diff --git "a/\346\236\227\351\221\253/2022.03.25/model/config/db.js" "b/\346\236\227\351\221\253/2022.03.25/model/config/db.js" index e1b143475ee09e95e6de0637d7af3fac6d05c55e..90011186d9fb30d134c3135edb9176a8389d72ca 100644 --- "a/\346\236\227\351\221\253/2022.03.25/model/config/db.js" +++ "b/\346\236\227\351\221\253/2022.03.25/model/config/db.js" @@ -8,11 +8,3 @@ let dbconfig = { } module.exports = dbconfig; - -//dbconfig.key(); - -// json 非常重要!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -// 其实它很单纯,看到 { 开头 }结尾就是json ,它是 key val 形式 ,key 就是 类型数组的键名,value 是对应的值 - -// value 不限定类型 \ No newline at end of file diff --git "a/\346\236\227\351\221\253/2022.03.25/model/home/controller/BaseController.js" "b/\346\236\227\351\221\253/2022.03.25/model/home/controller/BaseController.js" index 8d808f819a52672f1c650c26549e4882f6330cff..bae341875edca51a8870be30e8bcd8c7bc18fe52 100644 --- "a/\346\236\227\351\221\253/2022.03.25/model/home/controller/BaseController.js" +++ "b/\346\236\227\351\221\253/2022.03.25/model/home/controller/BaseController.js" @@ -8,7 +8,7 @@ class BaseController { this.req = req; this.res = res; this.nunjucks = nunjucks; - this.nunjucks.configure('./home/html', { autoescape: true });//配置模板的目录 + this.nunjucks.configure('./home/html', { autoescape: true }); } @@ -17,7 +17,6 @@ class BaseController { } getSession(key) { - //console.log(this.req.session); return this.req.session[key]; } @@ -26,12 +25,9 @@ class BaseController { } getCookie(key) { - //console.log('cookie json'); - //console.log(this.req.cookie); return this.req.cookie[key]; } - display(path, data) { return this.nunjucks.render(path, data); } diff --git "a/\346\236\227\351\221\253/2022.03.25/model/home/controller/UserController.js" "b/\346\236\227\351\221\253/2022.03.25/model/home/controller/UserController.js" index ecc6e85a7d84e15b6c06c0e8b9bbd45a03561d05..3882a36ca0c56714ab1dada4457f863e1721d374 100644 --- "a/\346\236\227\351\221\253/2022.03.25/model/home/controller/UserController.js" +++ "b/\346\236\227\351\221\253/2022.03.25/model/home/controller/UserController.js" @@ -28,10 +28,7 @@ class UserController extends BaseController { return await user.update({name:'admin2'},{id:3}); } - /** - * 前台用户注册页面 - * @returns - */ + async userReg(){ return this.display("userReg.html"); } @@ -48,7 +45,7 @@ class UserController extends BaseController { try{ let userList = await user.find({name:'demo',password:'123456'}); - return JSON.stringify(userList);//就是把对象转成json格式 + return JSON.stringify(userList); }catch(err){ console.log(err); diff --git "a/\346\236\227\351\221\253/2022.03.25/model/home/controller/index.js" "b/\346\236\227\351\221\253/2022.03.25/model/home/controller/index.js" index ca95476ab8e5eb0d66295cf3c4eb158122781bcd..0322a4a4fcbc06179cd43384b286add763c0745f 100644 --- "a/\346\236\227\351\221\253/2022.03.25/model/home/controller/index.js" +++ "b/\346\236\227\351\221\253/2022.03.25/model/home/controller/index.js" @@ -6,7 +6,6 @@ let index={ index:async function(req,res){ let mysql = require("../../model/base"); let date = req.query['date']; - //console.log('date-----'+date); let sql = 'select * from number where date=?'; let result= await mysql.query(sql,date,res); @@ -36,7 +35,7 @@ let index={ let mysql = require("../../model/base"); let date = req.query['date']; - let sql = 'select * from number order by id desc limit 1 ';//取出最先的一条数据 + let sql = 'select * from number order by id desc limit 1 '; let result= await mysql.query(sql,date,res); console.log(result); diff --git "a/\346\236\227\351\221\253/2022.03.25/untis/ArrayHelp.js" "b/\346\236\227\351\221\253/2022.03.25/untis/ArrayHelp.js" index 15c59c52ac89c5047dee5a132ded95facfb96d21..2c3ea65148d13ad4d7b01c0d847a2aaf7f4c73a6 100644 --- "a/\346\236\227\351\221\253/2022.03.25/untis/ArrayHelp.js" +++ "b/\346\236\227\351\221\253/2022.03.25/untis/ArrayHelp.js" @@ -3,7 +3,7 @@ let ArrayHelp={ buildKeyAndVal:function(String,firstSym,sendSym){ if(!String) return []; - let strArr = String.split(firstSym);// ['name=demo','password=23']; + let strArr = String.split(firstSym); let vals = {}; for (let ky in strArr) { let val = strArr[ky];