图书管理系统
前言
课程设计,要求如下
流程
基本思路,直接插入mysql,然后查询mysql即可
前端采用几个按钮切换功能及显示,直接部署到cloudflare page
上,这样也可以直接用cloudflare D1数据库
数据集来源
分析数据集格式及建表
数据格式如下
书名 | 作者 | 出版社 | 关键词 | 摘要 | 中国图书分类号 | 出版年月 |
---|
写成mysql
语句, 建表
CREATE DATABASE booksmanager; |
但这里先不要直接链接mysql建表,用python先预处理数据,分析长度以后再建表,然后插入数据库,python示例如下
# @Time : 2024/12/7 15:06 |
至此建表结束
写查询语句
根据题意写出mysql语句完成逻辑即可
获取第i本图书
select * from books limit i, 1
需要注意的是索引从0开始
查找一本图书
简单实现即可,这里要细化还是比较难的
输入:
- 书名(必须)
- 作者(可选)
- 出版社(可选)
输出:
为了优化sql语句,不需要全部都输出,只输出名称、作者、出版社、发行日期
模糊
select name,author,publisher,publish_date from books where name like "%道家文化与中医学%"; |
精确
select name,author,publisher,publish_date from books where name = "道家文化与中医学"; |
插入图书
insert into books (name, author, publisher, keyword, excerpt, category_num, publish_date) values (%s, %s, %s, %s, %s, %s, %s)", (你的数据1)) |
删除图书
模糊
select name,author,publisher,publish_date from books where name like "%道家文化与中医学%"; |
精确
select name,author,publisher,publish_date from books where name = "道家文化与中医学"; |
查询以后删除,删除只会有精确删除
delete from books where name = "道家文化与中医学"; |
输出所有图书
这就不说了
网页实现
大概长这样
<!DOCTYPE html> |
导入数据库到cloudflare kv
先导出sql文件
>mysqldump -u twoonefour -p booksmanager > booksmanager.sql
注意,这里sql数据库和kv不兼容,不要使用这个sql文件导入
手动在刚才导入数据库的py文件里写入
with open("data.sql", "w", encoding="utf-8") as f: |
创建数据库
npx wrangler d1 create booksmanager –remote
导入数据
npx wrangler d1 execute booksmanager –remote –file=booksmanager.sql
写入wrangler.toml
[[d1_databases]] |
根据上面sql语句创建index.js用于worker后端
后端worker设计
export default { |
api接口如下
endpoint | description | params | method |
---|---|---|---|
/api/select_all | 查询所有书籍 | index=123 | GET |
/api/select_book_by_index | 根据书号查询书 | index=xxx | GET |
/api/select_book | 模糊查询书籍 | book_name=xxxx | GET |
/api/precise_select_book | 精确查询 | book_name=xxx | GET |
/api/precise_delete_book | 精确删除书籍 | book_name=xxx | GET |
/api/insert_book | 添加书籍 | name, author, publisher, keyword, excerpt, category_num, publish_date | GET |
前端静态网页设计
前端真不熟,基本靠gpt
主要就是解决表格渲染问题(查询书籍)
写完以后直接上传page,然后分配即可
展示环节
最终预览请移步
视频展示
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 TwoOnefour的博客小窝!
评论