目录
(2)创建自己的路由文件:路由中间件 —— 接口文件(API)
1.REST风格:是一个基于web标准的架构。使用的是http协议。http协议的特点 —- 无状态协议
2.一个接口就是一个资源,这些资源的获取是通过http的标准方法来实现的
1.关系型数据库:用二维表格存放数据。有行、列之分。一个关系就是一张表格,一个数据库中有若干个表格。
4.SQL:结构化查询语言(Structure Query Language),是关系型数据库的标准查询语言
A.前端数据如何发送给后台:
a.get方式:数据绑定在url一起发送给后台
b.post方式:数据绑定在body上发送给客户端
B.后端接收前端的数据:
a.对于get方式:req.query.参数名
b.对于post方式:req.body.参数名
C.后端向前端响应数据:
a.res.send(数据):字符串或对象
b.res.json(数据):json格式的字符串
a.导入自定义的路由文件
b.配置路由路径:http://localhost:端口号 + 在app.js配置的路径 + 接口中给定的路径
注册接口:接收客户端的数据,将数据保存到文件中
登录接口:读取文件中的数据、对数据进行处理、判断
主页接口:向客户端响应数据
(1)通过浏览器地址发起的请求都是get方式
(2)在html页面中使用a标签发送的请求也是get方式
(3)location.href发送的请求也是get方式
B.创建Express项目时,如果修改了端口号,建议先运行项目看端口号是否可用
MongoDB、sqlite
varchar:字符串 int:整型
主键:唯一标识表格中一行记录的列称为主键列(值不能重复、不能为空)
select 列名1,列名2,… from 表名 [ where 条件]
- -- 查询student表的所有记录:* 是统配符代表所有列
- select * from student;
- select * from clazz;
- -- 查询student表中id、name、address列
- select id,name,address from student;
- select id,name,address
- from student;
- -- 条件查询:带where子句的查询
- -- 查询所有性别为'男'的记录
- select * from student where sex='男';
- -- 查询所有性别为'男' 并且年龄大于23岁的记录
- select * from student where sex='男' and age > 23;
- -- 查询所有性别为'男' 或年龄大于等于23岁的记录
- select * from student where sex='男' or age >= 23;
- -- 查询年龄在18~22岁之间的记录
- select * from student where age between 18 and 22;
- -- 查询地址是西安的学生信息
- select * from student where address = '西安';
- -- 查询地址是西安、渭南、咸阳的学生信息
- select * from student where address in ('西安','渭南','咸阳');
- -- 查询地址不是西安、渭南、咸阳的学生信息
- select * from student where address not in ('西安','渭南','咸阳');
- -- 模糊查询:使用like关键字,%通配符表示0个或多个字符,_表示1个字符
- -- 查询姓贾的学生记录
- select * from student where name like '贾%';
- -- 查询姓贾、名字两个字的学生记录
- select * from student where name like '贾_';
- -- 查询名字有3个字,最后一个字是'春'的学生记录
- select * from student where name like '__春';
insert into 表名(列名1,列名2…)values(值1,值2,……)
- -- 给student表插入一条记录
- insert into student values('1008','林黛玉','女',18,'镇江');
- -- 给student表的部分列插入数据:id、name、sex
- insert into student(id,name,sex) values('1014','武松','男');
delete from 表名 [where 条件]
- -- 删除id为1013的记录
- delete from student where id = '1013';
- -- 删除地址为'渭南'的记录
- delete from student where address = '渭南';
update 表名 set 列名1 = 值1,列名2=值2… [where 条件]
- -- 更新id为1014的记录的age、address字段
- update student set age=23,address='景阳冈' where id = '1014';