一、功能结构
图书管理系统分为用户界面和管理员界面,结构下图所示:
二、项目预览
用户界面:
管理界面:
三、数据库的设计
E—R图设计:
1、用户实体的设计
2、图书实体的设计
3、图书类别实体
4、图书借阅详情实体
四、数据表的设计
用户实体表的设计:
#创建数据库 CREATE DATABASE bookmanager; USE bookmanager; SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; #创建用户表user DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` INT(11) NOT NULL AUTO_INCREMENT, #用户主键id `username` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #用户名 `password` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #用户密码 `role` INT(255) NULL DEFAULT NULL COMMENT '角色 1学生 2管理员', #用户分类 `sex` VARCHAR(1) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #用户性别 `phone` CHAR(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #用户电话 PRIMARY KEY (`id`) USING BTREE ) ENGINE = INNODB AUTO_INCREMENT = 12 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; #插入数据 INSERT INTO `user` VALUES (1, 'xkj', 'xkj123', 1, '男', '13195648799'); INSERT INTO `user` VALUES (2, 'admin', '111111', 2, '男', '13198645975'); INSERT INTO `user` VALUES (3, '徐某人', 'xkj123', 1, '女', '13195648529'); INSERT INTO `user` VALUES (4, '肖淼', 'sdf78978', 1, '女', '13195698458'); SET FOREIGN_KEY_CHECKS = 1;
书籍表的设计:
#创建书籍表book DROP TABLE IF EXISTS `book`; CREATE TABLE `book` ( `id` INT(11) NOT NULL AUTO_INCREMENT, #图书表主键 `book_name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #图书名称 `type_id` INT(11) NULL DEFAULT NULL, #图书类别 `author` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #作者 `publish` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #出版社 `price` DOUBLE(10, 2) NULL DEFAULT NULL, #图书价格 `number` INT(11) NULL DEFAULT NULL, #图书数量 `status` INT(11) NULL DEFAULT 1 COMMENT '状态 1上架0下架', #借阅状态 `remark` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #图书描述 PRIMARY KEY (`id`) USING BTREE ) ENGINE = INNODB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; #插入数据 INSERT INTO `book` VALUES (1,'Java核心技术',1,'霍斯特曼','人民邮电出版社',69.00,16,1,'Java基础教学'); INSERT INTO `book` VALUES (2,'Tomcat与Java web',1,'孙卫琴','人民邮电出版社',119.00,16,1,'javaweb教学'); INSERT INTO `book` VALUES (3,'MySQL基础教程',1,'西泽梦路','人民邮电出版社',129.00,16,1,'MySQL基础教学'); INSERT INTO `book` VALUES (4, '西游记', 3, '吴承恩', '机械工业出版社', 23.00, 213, 1, '四大名著之一'); INSERT INTO `book` VALUES (6, 'SpringCloud微服务架构开发', 1, '黑马程序员', '人民邮电出版社', 28.00, 20, 1, '微服务实战开发'); INSERT INTO `book` VALUES (7, '水浒传', 3, '施耐庵 ', '人民文学出版社', 29.00, 30, 1, '四大名著之一');
图书类别表的设计:
#创建图书类别表 DROP TABLE IF EXISTS `book_type`; CREATE TABLE `book_type` ( `id` INT(11) NOT NULL AUTO_INCREMENT, #图书类别主键 `type_name` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #类别名称 `remark` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, #类别描述 PRIMARY KEY (`id`) USING BTREE ) ENGINE = INNODB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; #插入数据 INSERT INTO `book_type` VALUES (1, '技术', '技术类'); INSERT INTO `book_type` VALUES (2, '人文', '人文类'); INSERT INTO `book_type` VALUES (3, '小说', '人生情感小说');
图书借阅详情表的设计:
#创建图书借阅详情表 DROP TABLE IF EXISTS `borrowdetail`; CREATE TABLE `borrowdetail` ( `id` INT(11) NOT NULL AUTO_INCREMENT, #图书借阅详情表主键 `user_id` INT(11) NOT NULL, #用户id `book_id` INT(11) NOT NULL, #图书id `status` INT(11) NOT NULL COMMENT '状态 1在借2已还', #借阅状态 `borrow_time` BIGINT(20) NULL DEFAULT NULL, #借阅时间 `return_time` BIGINT(20) NULL DEFAULT NULL, #归还时间 PRIMARY KEY (`id`) USING BTREE ) ENGINE = INNODB AUTO_INCREMENT = 27 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT; #插入数据 INSERT INTO `borrowdetail` VALUES (1, 1, 2, 2, 1546414916391, 1546414948498); INSERT INTO `borrowdetail` VALUES (2, 1, 3, 2, 1546414932877, 1556417443285); INSERT INTO `borrowdetail` VALUES (3, 1, 2, 2, 1546416530026, 1546416640210); INSERT INTO `borrowdetail` VALUES (4, 1, 1, 2, 1546565100120, 1556334334816); INSERT INTO `borrowdetail` VALUES (5, 1, 4, 1, 1546565102870, NULL); INSERT INTO `borrowdetail` VALUES (6, 3, 1, 2, 1546565519776, 1556207839074); INSERT INTO `borrowdetail` VALUES (7, 3, 4, 1, 1546565522374, NULL); INSERT INTO `borrowdetail` VALUES (8, 1, 1, 1, 1556427836809, NULL); INSERT INTO `borrowdetail` VALUES (9, 4, 3, 1, 1556433544156, NULL); INSERT INTO `borrowdetail` VALUES (10, 7, 5, 1, 1556503388763, NULL); INSERT INTO `borrowdetail` VALUES (11, 8, 5, 2, 1556507260569, 1556507349243);
五、代码实现
以mysql最新版本8为例:
总结
通过图书管理系统这次设计,可以了解到开发一个项目,可以把它分成若干个小模块,分别有着不同的功能;然后分别为每个模块设计所需要的类;最后分步实现每个模块的功能。可以对Java流程开发程序流程有了整体的认识,为以后javaweb开发的学习奠定了基础。