吼吼吼,紧张的JavaEE阶段学习结束了,刚学完SSM框架,转眼这就到期末课设了。时间过得可真快啊。(然而我的框架使用和前端技术可能还是老八心爱的奥利给)
但是不论如何,课设就这么来了,这倒是个好机会,能把学过的技术栈给穿起来复习复习。刚好JavaEE阶段学了很多很多技术,但是都没有来得及写成博客梳理一番。借着这个项目,一边完成,一边梳理知识知识点,美汁汁~~
所以这个系列可能会连载许多篇 (我尽量) ,其中会有技术应用的,也会有完成结构的。当然,在完成的过程中一定是充满各种问题的,像是数据库设计的优化,程序结构设计的改善等等。
因此一些文章补充新的内容或者发生重构也肯定是经常的事情,我也真诚的希望在做的不好的地方可以获得你们宝贵的建议。
千里之行,始于足下,今天就从最开始的需求分析做起吧。
这个课设并不复杂,简单来说就是三个系统:
项目的需求暂时就只有这些,总体来说功能还算可以,下面我们先来粗略的建立数据库的表单吧。
暂时想来,这个项目不需要特别多的表单,目前想到的,需要七个表:
DROP TABLE IF EXISTS `vip`;
CREATE TABLE `vip` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`discount` double(10, 2) NULL DEFAULT 1.00,
`money` double(10, 2) NULL DEFAULT 0.00,
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '123456',
`phone` bigint(0) NULL DEFAULT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`birthday` date NULL DEFAULT NULL,
`due_time` date NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `code`(`code`) USING BTREE,
UNIQUE INDEX `phone`(`phone`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `staff`;
CREATE TABLE `staff` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`id_card` 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,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
员工数据暂时仅在网页上校验,在后台添加。
DROP TABLE IF EXISTS `room`;
CREATE TABLE `room` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`seat` int(0) NULL DEFAULT 50,
`type` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `film`;
CREATE TABLE `film` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`director` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`country` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`length` double NULL DEFAULT NULL,
`release_time` date NULL DEFAULT NULL,
`offline_time` date NULL DEFAULT NULL,
`language` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`introduction` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `film_post`;
CREATE TABLE `film_post` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`dir` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`film_id` int(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `film_id`(`film_id`) USING BTREE,
CONSTRAINT `film_id` FOREIGN KEY (`film_id`) REFERENCES `film` (`id`) ON DELETE SET NULL ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `screening_plan`;
CREATE TABLE `screening_plan` (
`price` decimal(10, 2) NOT NULL,
`room_id` int(0) NULL DEFAULT NULL,
`film_id` int(0) NULL DEFAULT NULL,
`time` time(0) NOT NULL,
`date` date NOT NULL,
`id` int(0) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`) USING BTREE,
INDEX `film`(`film_id`) USING BTREE,
INDEX `room`(`room_id`) USING BTREE,
CONSTRAINT `room` FOREIGN KEY (`room_id`) REFERENCES `room` (`id`) ON DELETE SET NULL ON UPDATE RESTRICT,
CONSTRAINT `film` FOREIGN KEY (`film_id`) REFERENCES `film` (`id`) ON DELETE SET NULL ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
DROP TABLE IF EXISTS `record`;
CREATE TABLE `record` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`time` datetime(0) NULL DEFAULT NULL,
`plan_id` int(0) NULL DEFAULT NULL,
`phone` bigint(0) NULL DEFAULT NULL,
`seat_id` int(0) NULL DEFAULT NULL,
`money` double(10, 2) NULL DEFAULT NULL,
`code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `plan`(`plan_id`) USING BTREE,
CONSTRAINT `plan` FOREIGN KEY (`plan_id`) REFERENCES `screening_plan` (`id`) ON DELETE SET NULL ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
nice~~~~
设置好了数据库,接下来就是设计对应的model里面的实体类了。为了方便查询,命名尽量同数据库中名称相同,但是数据库中的下划线命名得改成驼峰命名 /doge。
表中有些使用外键连接的表在类中直接就设计成为对象了,这样在使用Mybatis进行映射时也方便。因此,像电影海报这样的表就没有必要映射成为一个类了,把地址属性封装成一个字符串放在电影中就好。
(20.6.24:假的!最好还是将海报设计成为一个类,这样在配置mapper文件时的resultMap时会方便一些。不单独设计成为一个类,管理海报会成为一个麻烦事)
另外,为了节省空间,没有放getter、setter方法。
(博主没有公司,所以使用none合情合理 /理直气壮.jpg)
package com.none.model;
public class Vip {
private int id;
private String idCard;
private double money;
private double discount;
private String birthday;
private String dueTime;
private String password;
private String code;
private String phone;
}
package com.none.model;
public class Record {
private int id;
private double money;
private String time;
private ScreeningPlan plan;
private String code;
private Room room;
private String phone;
}
package com.none.model;
import java.util.List;
public class Film {
private int id;
private double length;
private String releseTime;
private String offlineTime;
private String name;
private String introduction;
private String language;
private String country;
private String director;
private List<FilmPost> post;
}
package com.none.model;
public class ScreeningPlan {
private int id;
private double price;
private String time;
private Room room;
private Film film;
}
package com.none.model;
public class Room {
private int id;
private int seat;
private String name;
private String type;
}
package com.none.model;
public class Staff {
private int id;
private String password;
private String idCard;
private String name;
}
package com.none.model;
public class FilmPost {
private int id;
private int filmId;
private String dir;
}
发现错误或是不妥之处欢迎指正~~~
博客会继续更新的,也许忙着做就给忘了,所以有可能会腹泻式更新(博主的奇妙比喻)。
第二弹:【从零开始JavaEE课设】《影院系统》(二)编写持久层Mapper接口
20.6.24更新:新增了海报类,电影类聚合海报,将list中类型改成海报