教务管理系统(java+mysql+jdbc+Druid+三层架构)

1、项目要求

1.1数据库表描述

设计一个教务管理系统,要求如下:

    系统涉及的表有

                account表(账号表)

                teacher表(教师表)

                student表(学生表)

                course表 (课程表)

                score表(成绩表)

                clazz表(班级表)
    表中的字段,根据系统功能,自行设计,注意字段的约束,和主外键关系

1.2账号描述

该系统账号角色有3个,分别为管理员、老师、学生
        管理员可以添加、修改、删除老师和学生的全部信息,也可以查看所有老师和学生的全部信息
        老师只能查看、修改、删除自己的全部信息,可以查看自己班级学生的全部信息、修改、删除、添加某个学生的信息
        学生只能查看、修改、删除自己的全部信息

1.3功能描述

 功能描述如下:
        系统启动后,可以选择角色进行登录,只有账号和密码正确才能继续使用系统,否则一直在登录页面
        
        管理员登录成功后,可以根据功能选项对老师、学生信息进行增删改查操作
            查看所有班级信息
            查看指定班级信息
            修改指定班级信息
            添加班级信息
            删除指定班级信息
            
            查看所有课程信息
            查看指定课程信息
            修改指定课程信息
            添加课程信息
            删除指定课程信息
        
            查看所有老师信息
            查看指定老师信息
            修改指定老师信息
            删除指定老师信息
            添加老师信息
            
            查看所有学生信息
            查看指定学生信息
            添加学生信息
            修改指定学生信息
            删除指定学生信息
            查看所有学生成绩信息
            查看指定学生成绩信息
            查看指定班级所有学生成绩信息    
            查看所有班级指定科目成绩信息
            查看指定班级指定科目成绩信息
            
        老师登录成功后,可以根据功能选项对自己的信息进行增删改查操作,可以对所有学生信息进行增删改查操作
            查看自己的信息
            修改自己的信息
            删除自己的信息
            
            查看自己班级所有学生信息
            查看自己班级指定学生信息
            添加自己班级学生信息
            修改自己班级指定学生信息
            删除自己班级指定学生信息
            查看自己班级所有学生所有科目成绩信息
            查看自己班级所有学生指定科目成绩信息
            查看自己班级指定学生所有科目成绩信息
            查看自己班级指定学生指定科目成绩信息
            
        学生登录成功后,可以根据功能选项对自己的信息进行查看、修改、删除操作
            查看自己的信息
            修改自己的信息
            删除自己的信息
            查看自己所有科目成绩信息
            查看自己指定科目成绩信息
            查看自己班级所有学生所有科目成绩信息
            查看自己班级所有学生指定科目成绩信息
            查看自己班级指定学生所有科目成绩信息
            查看自己班级指定学生指定科目成绩信息

2、数据库表设计

2.1实现代码

CREATE DATABASE IF NOT EXISTS eamsystem;   #Educational Administration Management System
USE eamsystem;#  account表(账号表)
CREATE TABLE IF NOT EXISTS account(
atid	INT PRIMARY KEY,
atname	VARCHAR(20) NOT NULL,
atpassword VARCHAR(20) NOT NULL
);INSERT INTO account(atid,atname,atpassword) 
VALUES
(101,'墨尘','ad001'),
(102,'修远','ad002'),
(103,'白洛','ad003'),
(104,'思羽','ad004');#clazz表(班级表)
CREATE TABLE IF NOT EXISTS clazz(
clazzid	INT PRIMARY KEY,
clname	VARCHAR(20) NOT NULL
);
INSERT INTO clazz VALUES(11,'1班'),(12,'2班'),(13,'3班');# teacher表
CREATE TABLE IF NOT EXISTS teacher(
teacherid INT PRIMARY KEY ,
thname VARCHAR(20) NOT NULL,
thage INT NOT NULL,
thsex CHAR NOT NULL,
clazzid INT ,      # 外键约束   同步修改,删除设置为null
thpassword VARCHAR(20) NOT NULL ,
CONSTRAINT teacher_clid FOREIGN KEY (clazzid) REFERENCES clazz(clazzid) ON UPDATE CASCADE ON DELETE RESTRICT
); 
INSERT INTO teacher VALUES
(201,'老师1',30,'男',11,'th001'),
(202,'老师2',40,'男',11,'th002'),
(203,'老师3',28,'女',12,'th003'),
(204,'老师4',29,'女',12,'th004'),
(205,'老师5',30,'女',12,'th005'),
(206,'老师6',40,'女',13,'th006');#student表
CREATE TABLE IF NOT EXISTS student(
studentid INT PRIMARY KEY ,
stname VARCHAR(20) NOT NULL ,
stsex	CHAR NOT NULL ,
stage	INT  NOT NULL,
clazzid INT,# 外键约束   同步修改,删除设置为null
stpassword VARCHAR(20) NOT NULL ,
CONSTRAINT student_clid FOREIGN KEY (clazzid) REFERENCES clazz(clazzid) ON UPDATE CASCADE ON DELETE RESTRICT
);
INSERT INTO student VALUES
(301,'学生1','男',15,11,'st001'),
(302,'学生2','男',14,11,'st002'),
(303,'学生3','女',14,11,'st003'),
(304,'学生4','男',14,12,'st004'),
(305,'学生5','男',14,12,'st005'),
(306,'学生6','女',14,12,'st006'),
(307,'学生7','女',14,12,'st007'),
(308,'学生8','女',14,13,'st008'),
(309,'学生9','女',14,13,'st009'),
(310,'学生10','男',14,13,'st10');#course表(课程表)
CREATE TABLE IF NOT EXISTS course(
courseid INT PRIMARY KEY,
csname	VARCHAR(20) NOT NULL,
teacherid INT,           #修改同步,删除删除设置为null
CONSTRAINT coutse_tid FOREIGN KEY (teacherid) REFERENCES teacher(teacherid) ON UPDATE CASCADE ON DELETE RESTRICT
);
#[CONSTRAINT <外键约束名称>] FOREIGN KEY(从表的某个字段) references 主表名(被参考字段)
#CONSTRAINT fk_emp1_dept_id FOREIGN KEY (department_id) REFERENCES dept1(dept_id)INSERT INTO course VALUES
(401,'Python',201),
(402,'C#',202),
(403,'JAVA',203),
(404,'Go',204),
(405,'C语言',205),
(406,'Hadoop',206);#score表(成绩表)
CREATE TABLE IF NOT EXISTS score(
studentid INT NOT NULL,    #  修改同步,删除同步,删除学生信息的时候要删除对应成绩信息
courseid INT ,             #  修个课程编号时同步,删除设置为null
grade INT ,
CONSTRAINT score_stid FOREIGN KEY (studentid) REFERENCES student(studentid) ON UPDATE CASCADE ON DELETE CASCADE ,
CONSTRAINT score_csid FOREIGN KEY (courseid) REFERENCES course(courseid) ON UPDATE CASCADE ON DELETE RESTRICT
);
INSERT INTO score (studentid,courseid,grade) VALUES(301,401,60);
INSERT INTO score (studentid,courseid,grade) VALUES(301,402,70);
INSERT INTO score (studentid,courseid,grade) VALUES(301,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(301,404,99);
INSERT INTO score (studentid,courseid,grade) VALUES(301,405,50);
INSERT INTO score (studentid,courseid,grade) VALUES(301,406,80);INSERT INTO score (studentid,courseid,grade) VALUES(302,401,77);
INSERT INTO score (studentid,courseid,grade) VALUES(302,402,99);
INSERT INTO score (studentid,courseid,grade) VALUES(302,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(302,404,66);
INSERT INTO score (studentid,courseid,grade) VALUES(302,405,60);
INSERT INTO score (studentid,courseid,grade) VALUES(302,406,70);INSERT INTO score (studentid,courseid,grade) VALUES(303,401,90);
INSERT INTO score (studentid,courseid,grade) VALUES(303,402,80);
INSERT INTO score (studentid,courseid,grade) VALUES(303,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(303,404,77);
INSERT INTO score (studentid,courseid,grade) VALUES(303,405,66);
INSERT INTO score (studentid,courseid,grade) VALUES(303,406,50);INSERT INTO score (studentid,courseid,grade) VALUES(304,401,80);
INSERT INTO score (studentid,courseid,grade) VALUES(304,402,40);
INSERT INTO score (studentid,courseid,grade) VALUES(304,403,80);
INSERT INTO score (studentid,courseid,grade) VALUES(304,404,97);
INSERT INTO score (studentid,courseid,grade) VALUES(304,405,50);
INSERT INTO score (studentid,courseid,grade) VALUES(304,406,88);INSERT INTO score (studentid,courseid,grade) VALUES(305,401,77);
INSERT INTO score (studentid,courseid,grade) VALUES(305,402,88);
INSERT INTO score (studentid,courseid,grade) VALUES(305,403,90);
INSERT INTO score (studentid,courseid,grade) VALUES(305,404,68);
INSERT INTO score (studentid,courseid,grade) VALUES(305,405,76);
INSERT INTO score (studentid,courseid,grade) VALUES(305,406,89);INSERT INTO score (studentid,courseid,grade) VALUES(306,401,75);
INSERT INTO score (studentid,courseid,grade) VALUES(306,402,77);
INSERT INTO score (studentid,courseid,grade) VALUES(306,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(306,404,90);
INSERT INTO score (studentid,courseid,grade) VALUES(306,405,64);
INSERT INTO score (studentid,courseid,grade) VALUES(306,406,50);INSERT INTO score (studentid,courseid,grade) VALUES(307,401,70);
INSERT INTO score (studentid,courseid,grade) VALUES(307,402,90);
INSERT INTO score (studentid,courseid,grade) VALUES(307,403,90);
INSERT INTO score (studentid,courseid,grade) VALUES(307,404,88);
INSERT INTO score (studentid,courseid,grade) VALUES(307,405,99);
INSERT INTO score (studentid,courseid,grade) VALUES(307,406,95);INSERT INTO score (studentid,courseid,grade) VALUES(308,401,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,402,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,403,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,404,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,405,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,406,50);INSERT INTO score (studentid,courseid,grade) VALUES(309,401,96);
INSERT INTO score (studentid,courseid,grade) VALUES(309,402,75);
INSERT INTO score (studentid,courseid,grade) VALUES(309,403,51);
INSERT INTO score (studentid,courseid,grade) VALUES(309,404,76);
INSERT INTO score (studentid,courseid,grade) VALUES(309,405,85);
INSERT INTO score (studentid,courseid,grade) VALUES(309,406,64);INSERT INTO score (studentid,courseid,grade) VALUES(310,401,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,402,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,403,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,404,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,405,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,406,100);/*
管理员登录成功后,可以根据功能选项对老师、学生信息进行增删改查操作*/#查看所有班级信息
SELECT * FROM clazz;
#查看指定班级信息
SELECT * FROM clazz WHERE clazzid = 11;
#修改指定班级信息
SELECT * FROM clazz;
UPDATE clazz SET  clname = '1班' WHERE clazzid = 11;
UPDATE clazz SET  clname = '5班' WHERE clazzid = 11;
#添加班级信息
INSERT INTO clazz(clazzid,clname) VALUE(14,'4班');
#删除指定班级信息
DELETE FROM clazz WHERE  clazzid=14; 		#查看所有课程信息
SELECT * FROM course;
#查看指定课程信息
SELECT * FROM course WHERE courseid=401;
#修改指定课程信息
SELECT * FROM course;
UPDATE course SET csname = 'Python',teacherid =  201 WHERE courseid = 401;
UPDATE course SET csname = '语文' , teacherid =  201  WHERE courseid = 401;
#添加课程信息
INSERT INTO course(courseid,csname,teacherid) VALUE (407,'数学',206);
#删除指定课程信息
DELETE FROM course WHERE courseid=407;#查看所有老师信息
SELECT * FROM teacher ;
#查看指定老师信息
SELECT * FROM teacher WHERE teacherid =201 ;
#修改指定老师信息
UPDATE teacher SET thname='老师1',thage=30,thsex='男',clazzid=11,thpassword='th001' WHERE teacherid = 201;
UPDATE teacher SET thname='老师8',thage=30,thsex='女',clazzid=11,thpassword='th001' WHERE teacherid = 201;
#添加老师信息
INSERT INTO teacher(teacherid,thname,thage,thsex,clazzid,thpassword) VALUES(207,'老师7',40,'男',13,'8888');
#删除指定老师信息
DELETE FROM teacher WHERE teacherid=207;#查看所有学生信息
SELECT * FROM student; 
#查看指定学生信息
SELECT * FROM student WHERE studentid=301;
#修改指定学生信息
UPDATE student SET stname='学生1',stsex='男',stage=15,clazzid=11,stpassword='st001' WHERE studentid = 301;
UPDATE student SET stname='我是学生',stsex='男',stage=15,clazzid=11,stpassword='st001' WHERE studentid = 301;
#添加学生信息
INSERT INTO student(studentid,stname,stsex,stage,clazzid,stpassword) VALUES(311,'学生55','女',14,13,'st008');
#删除指定学生信息
DELETE FROM student WHERE studentid=311;
#查看所有学生成绩信息
SELECT * FROM score;
#查看指定学生成绩信息
SELECT * FROM score WHERE studentid=301;
#查看指定班级所有学生成绩信息	
SELECT b.studentid,courseid,grade 
FROM clazz a,score b ,student c 
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND a.`clazzid`=11;#查看所有班级指定科目成绩信息
SELECT b.`studentid`,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c 
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND b.`courseid`=401;#查看指定班级指定科目成绩信息
SELECT a.clname '班级名称' , c.`studentid` '学生编号' ,b.`courseid` '课程编号',b.grade '成绩' 
FROM clazz a,score b ,student c 
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND b.`courseid`=401 AND a.`clazzid`=11 ;/*	
老师登录成功后,可以根据功能选项对自己的信息进行增删改查操作,可以对所有学生信息进行增删改查操作*/
#查看自己的信息
SELECT * FROM teacher WHERE teacherid = 201;
#修改自己的信息
UPDATE teacher SET thname='老师1',thage=30,thsex='男',clazzid=11,thpassword='th001' WHERE teacherid = 201;
UPDATE teacher SET thname='老师8',thage=30,thsex='女',clazzid=11,thpassword='th001' WHERE teacherid = 201;#删除自己的信息/*
SET FOREIGN_KEY_CHECKS = 0;  // 先设置外键约束检查关闭DROP TABLE table1; 
detele FROM TABLE WHERE ;// 删除表或数据SET FOREIGN_KEY_CHECKS = 1; // 开启外键约束检查,以保持表结构完整性
*/
SET FOREIGN_KEY_CHECKS = 0;  // 先设置外键约束检查关闭
DELETE FROM teacher WHERE teacherid=201;
INSERT INTO teacher VALUES
(201,'老师1',30,'男',11,'th001');	
SET FOREIGN_KEY_CHECKS = 1; // 开启外键约束检查,以保持表结构完整性
SELECT * FROM teacher;#查看自己班级所有学生信息
SELECT *
FROM student 
WHERE clazzid=11;
#查看自己班级指定学生信息
SELECT *
FROM student
WHERE  clazzid = 11 AND studentid=301;#添加自己班级学生信息
SELECT clazzid FROM teacher WHERE teacherid=201;
INSERT INTO student(studentid,stname,stsex,stage,clazzid,stpassword) 
VALUES(311,'dddd','男',14,11,'st002');
SELECT * FROM student;#修改自己班级指定学生信息
SELECT clazzid FROM teacher WHERE teacherid=201;
UPDATE student SET stname='学生1',stsex='男',stage=15,clazzid=11,stpassword='st001' WHERE studentid = 301;
UPDATE student SET stname='我是学生',stsex='男',stage=15,clazzid=11,stpassword='st001' WHERE studentid = 301;#删除自己班级指定学生信息
SET FOREIGN_KEY_CHECKS = 0;  // 先设置外键约束检查关闭
DELETE FROM student WHERE studentid=311;
SET FOREIGN_KEY_CHECKS = 1; // 开启外键约束检查,以保持表结构完整性
INSERT INTO student VALUES
(301,'学生1','男',15,11,'st001');#下述功能重复,这里就没有写了
#查看自己班级所有学生所有科目成绩信息
#查看自己班级所有学生指定科目成绩信息
#查看自己班级指定学生所有科目成绩信息
#查看自己班级指定学生指定科目成绩信息/*			
学生登录成功后,可以根据功能选项对自己的信息进行查看、修改、删除操作
*/
#查看自己的信息
SELECT * FROM student WHERE studentid=301;
#修改自己的信息
UPDATE student SET stname='学生10',stsex='男',stage=15,clazzid=11,stpassword='st010' WHERE studentid = 301;
UPDATE student SET stname='我是学生',stsex='男',stage=15,clazzid=11,stpassword='st010' WHERE studentid = 301;
#删除自己的信息
DELETE FROM student WHERE studentid=302;
#查看自己所有科目成绩信息
SELECT * FROM score WHERE studentid=301;#查看自己指定科目成绩信息
SELECT * FROM score WHERE  studentid=301 AND courseid=401  ;#查看自己班级所有学生所有科目成绩信息SELECT b.studentid,b.`courseid`,b.`grade`
FROM student a ,score b,course c
WHERE a.`studentid` = b.`studentid` AND b.`courseid` = c.`courseid` AND a.`clazzid`=11;#查看自己班级所有学生指定科目成绩信息
SELECT b.studentid,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c 
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND b.`courseid`=401 AND a.`clazzid`=11 ;#查看自己班级指定学生所有科目成绩信息
SELECT b.studentid,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c 
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND c.`studentid`=301 AND a.`clazzid`=11 ;#查看自己班级指定学生指定科目成绩信息
SELECT b.studentid,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c 
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND  a.`clazzid`=11   AND  c.`studentid`=301 AND b.`courseid`=401 ;

2.2数据库设计

2.2.1account表(管理员账号表)

CREATE TABLE IF NOT EXISTS account(
atid    INT PRIMARY KEY,
atname    VARCHAR(20) NOT NULL,
atpassword VARCHAR(20) NOT NULL
);
字段名含义类型主键外键非空
atid管理员账号INT
atname管理员姓名VARCHAR(20)
atpassword管理员密码VARCHAR(20)

account表 初始数据

INSERT INTO account(atid,atname,atpassword) 
VALUES
(101,'墨尘','ad001'),
(102,'修远','ad002'),
(103,'白洛','ad003'),
(104,'思羽','ad004');

2.2.2clazz表(班级表)

CREATE TABLE IF NOT EXISTS clazz(
clazzid	INT PRIMARY KEY,
clname	VARCHAR(20) NOT NULL
);
字段名含义类型主键外键非空
clazzid班级编号INT
clname班级名称VARCHAR(20)

clazz表 初始数据

INSERT INTO clazz VALUES(11,'1班'),(12,'2班'),(13,'3班');

2.2.3teacher表(教师表)

CREATE TABLE IF NOT EXISTS teacher(
teacherid INT PRIMARY KEY ,
thname VARCHAR(20) NOT NULL,
thage INT NOT NULL,
thsex CHAR NOT NULL,
clazzid INT ,      # 外键约束   同步修改,删除设置为null
thpassword VARCHAR(20) NOT NULL ,
CONSTRAINT teacher_clid FOREIGN KEY (clazzid) REFERENCES clazz(clazzid) ON UPDATE CASCADE ON DELETE RESTRICT
); 
字段名含义类型主键外键非空
teacherid教师账号INT
thname教师姓名VARCHAR(20)
thage教师年龄INT
thsex教师性别CHAR
clazzid所带班级编号INT
thpassword账号密码VARCHAR(20)

teacher表 初始数据

INSERT INTO teacher VALUES
(201,'老师1',30,'男',11,'th001'),
(202,'老师2',40,'男',11,'th002'),
(203,'老师3',28,'女',12,'th003'),
(204,'老师4',29,'女',12,'th004'),
(205,'老师5',30,'女',12,'th005'),
(206,'老师6',40,'女',13,'th006');

2.2.4student表(学生表)

#student表
CREATE TABLE IF NOT EXISTS student(
studentid INT PRIMARY KEY ,
stname VARCHAR(20) NOT NULL ,
stsex	CHAR NOT NULL ,
stage	INT  NOT NULL,
clazzid INT,# 外键约束   同步修改,删除设置为null
stpassword VARCHAR(20) NOT NULL ,
CONSTRAINT student_clid FOREIGN KEY (clazzid) REFERENCES clazz(clazzid) ON UPDATE CASCADE ON DELETE RESTRICT
);
字段名含义类型主键外键非空
studentid学生账号INT
stname学生姓名VARCHAR(20)
stsex学生性别CHAR
stage学生年龄INT
clazzid所在班级编号INT
stpassword密码VARCHAR(20)

student表初始数据

INSERT INTO student VALUES
(301,'学生1','男',15,11,'st001'),
(302,'学生2','男',14,11,'st002'),
(303,'学生3','女',14,11,'st003'),
(304,'学生4','男',14,12,'st004'),
(305,'学生5','男',14,12,'st005'),
(306,'学生6','女',14,12,'st006'),
(307,'学生7','女',14,12,'st007'),
(308,'学生8','女',14,13,'st008'),
(309,'学生9','女',14,13,'st009'),
(310,'学生10','男',14,13,'st10');

2.2.5course表(课程表)

#course表(课程表)
CREATE TABLE IF NOT EXISTS course(
courseid INT PRIMARY KEY,
csname	VARCHAR(20) NOT NULL,
teacherid INT,           #修改同步,删除删除设置为null
CONSTRAINT coutse_tid FOREIGN KEY (teacherid) REFERENCES teacher(teacherid) ON UPDATE CASCADE ON DELETE RESTRICT
);
字段名含义类型主键外键非空
courseid课程编号INT
csname课程名称VARCHAR(20)
teacherid教师账号(编号)INT

course表初始数据

INSERT INTO course VALUES
(401,'Python',201),
(402,'C#',202),
(403,'JAVA',203),
(404,'Go',204),
(405,'C语言',205),
(406,'Hadoop',206);

2.2.6score表(成绩表)

字段名含义类型主键外键非空
studentidINT
courseidINT
gradeINT

score表初始数据

INSERT INTO score (studentid,courseid,grade) VALUES(301,401,60);
INSERT INTO score (studentid,courseid,grade) VALUES(301,402,70);
INSERT INTO score (studentid,courseid,grade) VALUES(301,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(301,404,99);
INSERT INTO score (studentid,courseid,grade) VALUES(301,405,50);
INSERT INTO score (studentid,courseid,grade) VALUES(301,406,80);INSERT INTO score (studentid,courseid,grade) VALUES(302,401,77);
INSERT INTO score (studentid,courseid,grade) VALUES(302,402,99);
INSERT INTO score (studentid,courseid,grade) VALUES(302,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(302,404,66);
INSERT INTO score (studentid,courseid,grade) VALUES(302,405,60);
INSERT INTO score (studentid,courseid,grade) VALUES(302,406,70);INSERT INTO score (studentid,courseid,grade) VALUES(303,401,90);
INSERT INTO score (studentid,courseid,grade) VALUES(303,402,80);
INSERT INTO score (studentid,courseid,grade) VALUES(303,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(303,404,77);
INSERT INTO score (studentid,courseid,grade) VALUES(303,405,66);
INSERT INTO score (studentid,courseid,grade) VALUES(303,406,50);INSERT INTO score (studentid,courseid,grade) VALUES(304,401,80);
INSERT INTO score (studentid,courseid,grade) VALUES(304,402,40);
INSERT INTO score (studentid,courseid,grade) VALUES(304,403,80);
INSERT INTO score (studentid,courseid,grade) VALUES(304,404,97);
INSERT INTO score (studentid,courseid,grade) VALUES(304,405,50);
INSERT INTO score (studentid,courseid,grade) VALUES(304,406,88);INSERT INTO score (studentid,courseid,grade) VALUES(305,401,77);
INSERT INTO score (studentid,courseid,grade) VALUES(305,402,88);
INSERT INTO score (studentid,courseid,grade) VALUES(305,403,90);
INSERT INTO score (studentid,courseid,grade) VALUES(305,404,68);
INSERT INTO score (studentid,courseid,grade) VALUES(305,405,76);
INSERT INTO score (studentid,courseid,grade) VALUES(305,406,89);INSERT INTO score (studentid,courseid,grade) VALUES(306,401,75);
INSERT INTO score (studentid,courseid,grade) VALUES(306,402,77);
INSERT INTO score (studentid,courseid,grade) VALUES(306,403,88);
INSERT INTO score (studentid,courseid,grade) VALUES(306,404,90);
INSERT INTO score (studentid,courseid,grade) VALUES(306,405,64);
INSERT INTO score (studentid,courseid,grade) VALUES(306,406,50);INSERT INTO score (studentid,courseid,grade) VALUES(307,401,70);
INSERT INTO score (studentid,courseid,grade) VALUES(307,402,90);
INSERT INTO score (studentid,courseid,grade) VALUES(307,403,90);
INSERT INTO score (studentid,courseid,grade) VALUES(307,404,88);
INSERT INTO score (studentid,courseid,grade) VALUES(307,405,99);
INSERT INTO score (studentid,courseid,grade) VALUES(307,406,95);INSERT INTO score (studentid,courseid,grade) VALUES(308,401,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,402,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,403,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,404,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,405,50);
INSERT INTO score (studentid,courseid,grade) VALUES(308,406,50);INSERT INTO score (studentid,courseid,grade) VALUES(309,401,96);
INSERT INTO score (studentid,courseid,grade) VALUES(309,402,75);
INSERT INTO score (studentid,courseid,grade) VALUES(309,403,51);
INSERT INTO score (studentid,courseid,grade) VALUES(309,404,76);
INSERT INTO score (studentid,courseid,grade) VALUES(309,405,85);
INSERT INTO score (studentid,courseid,grade) VALUES(309,406,64);INSERT INTO score (studentid,courseid,grade) VALUES(310,401,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,402,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,403,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,404,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,405,100);
INSERT INTO score (studentid,courseid,grade) VALUES(310,406,100);

2.3E-R图

3、JAVA后端+JDBC+三层结构实现

3.1依赖包

说明:可根据自己电脑安装的mysql版本自行搜索下载对应版本的包依赖,这里就不提供依赖包。

 3.2Druid连接池的database.properties配置文件

# 连接设置
driver=com.mysql.cj.jdbc.Driver
#eamsystem  是上文创建的数据库,六张表都在这个数据库中
url=jdbc:mysql://localhost:3306/eamsystem
username=你自己的数据库用户名
password=你自己的密码# 初始化连接,连接池连接对象数量
initialSize=10#最大连接数
maxActive=30#超时等待时间(毫秒为单位)
maxWait=3000

3.3目录结构

3.4具体代码

3.4.1dao层(com.nanchu.dao)

AccountDao接口

package com.nanchu.dao;import com.nanchu.entity.Account;import java.util.List;/*** @Author 南初* @Create 2024/3/10 10:08* @Version 1.0*/
public interface AccountDao {//添加int accountInsert(Account account);//删除int accountDelete(int atid);//修改int accountUpdate(Account account);//查询单个Account accountSelectOne(int atid);//查询所有List<Account> accountSelectAll();
}
ClazzDao接口
package com.nanchu.dao;import com.nanchu.entity.Clazz;import java.util.List;/*** @Author 南初* @Create 2024/3/10 10:09* @Version 1.0*/
public interface ClazzDao {//添加int clazzInsert(Clazz clazz);//删除int clazzDelete(int clazzid);//修改int clazzUpdate(Clazz clazz);//查询单个Clazz clazzSelectOne(int clazzid);//查询所有List<Clazz> clazzSelectAll();
}
CourseDao接口
package com.nanchu.dao;import com.nanchu.entity.Course;import java.util.List;/*** @Author 南初* @Create 2024/3/10 10:10* @Version 1.0*/
public interface CourseDao {//添加int courseInsert(Course course);//删除int courseDelete(int courseid);//修改int courseUpdate(Course course);//查询单个Course courseSelectOne(int courseid);//查询所有List<Course> courseSelectAll();
}
ScoreDao接口
package com.nanchu.dao;import com.nanchu.entity.Account;
import com.nanchu.entity.Score;import java.util.List;/*** @Author 南初* @Create 2024/3/10 10:11* @Version 1.0*/
public interface ScoreDao {//添加int scoreInsert(Score score);//删除int scoreDelete(int studentid);//修改int scoreUpdate(Score score);//查询单个学生全部成绩List<Score> scoreSelectOne(int studentid);//查询所有List<Score> scoreSelectAll();// #查看自己指定科目成绩信息Score selectStudentCourse(int studentid,int courseid);}
StudentDao接口
package com.nanchu.dao;import com.nanchu.entity.Student;import java.util.List;/*** @Author 南初* @Create 2024/3/10 10:11* @Version 1.0*/
public interface StudentDao {//添加int studentInsert(Student student);//删除int studentDelete(int studentid);//修改int studentUpdate(Student student);//查询单个Student studentSelectOne(int studentid);//查询所有List<Student> studentSelectAll();
}
TeacherDao接口
package com.nanchu.dao;import com.nanchu.entity.Teacher;import java.util.List;/*** @Author 南初* @Create 2024/3/10 10:11* @Version 1.0*/
public interface TeacherDao {//添加int teacherInsert(Teacher teacher);//删除int teacherDelete(int teacherid);//修改int teacherUpdate(Teacher teacher);//查询单个Teacher teacherSelectOne(int teacherid);//查询所有List<Teacher> teacherSelectAll();
}
QueryOtherWay接口
package com.nanchu.dao;import com.nanchu.entity.Score;
import com.nanchu.entity.Student;import java.util.List;/*** @Author 南初* @Create 2024/3/11 8:28* @Version 1.0*/
public interface QueryOtherWay {/***#查看自己班级所有学生信息**/List<Student> allStudentClazz(int clazzid);/*** 查看自己班级指定学生信息*/List<Student> OneStudentClazz(int clazzid,int studentid);/*** #查看所有班级指定科目成绩信息*/List<Score> allClazzOneCourseScore(int courseid);/***自己班级所有学生所有科目成绩信息* @return*/List<Score> allStudentAllCourseScore(int clazzid);/***自己班级所有学生指定科目成绩信息* @return*/List<Score> allStudentOneCourseScore(int clazzid,int courseid);/***自己班级指定学生所有科目成绩信息* @return*/List<Score> oneStudentAllCourseScore(int clazzid,int studentid);/*** 自己班级指定学生指定科目成绩信息**/List<Score> oneStudentOneCourseScore(int clazzid,int studentid,int courseid);}

3.4.2dao.imlp层(com.nanchu.dao.impl)

AccountDaoImpl实现类
package com.nanchu.dao.impl;import com.nanchu.dao.AccountDao;
import com.nanchu.entity.Account;
import com.nanchu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;import java.sql.SQLException;
import java.util.List;/*** @Author 南初* @Create 2024/3/10 10:09* @Version 1.0*/
public class AccountDaoImpl implements AccountDao {// 创建QueryRunner对象,并传递一个数据源对象private QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());@Overridepublic int accountInsert(Account account) {return 0;}@Overridepublic int accountDelete(int atid) {return 0;}@Overridepublic int accountUpdate(Account account) {return 0;}@Overridepublic Account accountSelectOne(int atid) {// 查询一个数据,使用BeanHandler将记录转换为对象BeanHandler<Account> account = new BeanHandler<Account>(Account.class);String sql = "SELECT * FROM `account` WHERE `atid`=?;";try {return queryRunner.query(sql, account, atid);} catch (SQLException e) {e.printStackTrace();}return null;}@Overridepublic List<Account> accountSelectAll() {return null;}
}
ClazzDaoImpl实现类
package com.nanchu.dao.impl;import com.nanchu.dao.ClazzDao;
import com.nanchu.entity.Clazz;
import com.nanchu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;/*** @Author 南初* @Create 2024/3/10 12:24* @Version 1.0*/
public class ClazzDaoImpl implements ClazzDao {// 创建QueryRunner对象,并传递一个数据源对象private QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());// 插入@Overridepublic int clazzInsert(Clazz clazz) {/** #添加班级信息INSERT INTO clazz(clazzid,clname) VALUE(14,'4班');*/String sql = "INSERT INTO `clazz`(`clazzid`,`clname`)VALUES(?,?);";Object[] args = {clazz.getClazzid(), clazz.getClname()};try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}//删除@Overridepublic int clazzDelete(int clazzid) {/*#删除指定班级信息DELETE FROM clazz WHERE  clazzid=14;* */String sql = "DELETE FROM `clazz` WHERE `clazzid` = ?;";try {return queryRunner.update(sql, clazzid);} catch (SQLException e) {e.printStackTrace();}return 0;}//修改@Overridepublic int clazzUpdate(Clazz clazz) {/** #修改指定班级信息SELECT * FROM clazz;UPDATE clazz SET  clname = '1班' WHERE clazzid = 11;UPDATE clazz SET  clname = '5班' WHERE clazzid = 11;* */String sql = "UPDATE `clazz` SET `clname` = ? WHERE `clazzid`=?;";Object[] args = { clazz.getClname(),clazz.getClazzid()};try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}//查询单个@Overridepublic Clazz clazzSelectOne(int clazzid) {/*#查看指定班级信息SELECT * FROM clazz WHERE clazzid = 11;* */// 查询一个数据,使用BeanHandler将记录转换为对象BeanHandler<Clazz> clazz = new BeanHandler<Clazz>(Clazz.class);String sql = "SELECT * FROM `clazz` WHERE `clazzid`=?;";try {return queryRunner.query(sql, clazz, clazzid);} catch (SQLException e) {e.printStackTrace();}return null;}//查询所有@Overridepublic List<Clazz> clazzSelectAll() {/*#查看所有班级信息SELECT * FROM clazz;* */// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Clazz> clazzList = new BeanListHandler<Clazz>(Clazz.class);String sql = "SELECT * FROM `clazz`;";try {return queryRunner.query(sql, clazzList);} catch (SQLException e) {e.printStackTrace();}return null;}
}
CourseDaoImpl实现类
package com.nanchu.dao.impl;import com.nanchu.dao.CourseDao;
import com.nanchu.entity.Course;
import com.nanchu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;/*** @Author 南初* @Create 2024/3/10 12:42* @Version 1.0*/
public class CourseDaoImpl implements CourseDao {// 创建QueryRunner对象,并传递一个数据源对象private QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());@Overridepublic int courseInsert(Course course) {/*#添加课程信息INSERT INTO course(courseid,csname,teacherid) VALUE (407,'数学',206);* */String sql = "INSERT INTO `course`(`courseid`,`csname`,`teacherid`)VALUES(?,?,?);";Object[] args = { course.getCourseid(),course.getCsname(),course.getTeacherid() };try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic int courseDelete(int courseid) {/** #删除指定课程信息DELETE FROM course WHERE courseid=407;*/String sql = "DELETE FROM `course` WHERE `courseid` = ?;";try {return queryRunner.update(sql, courseid);} catch (SQLException e) {e.printStackTrace();}return 0;}// 修改@Overridepublic int courseUpdate(Course course) {/* #修改指定课程信息SELECT * FROM course;UPDATE course SET csname = 'Python',teacherid =  201 WHERE courseid = 401;UPDATE course SET csname = '语文' , teacherid =  201  WHERE courseid = 401;*/String sql = "UPDATE `course` SET `csname` = ?,`teacherid`=?WHERE `courseid`=?;";Object[] args = { course.getCsname(),course.getTeacherid(),course.getCourseid() };try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic Course courseSelectOne(int courseid) {/*#查看指定课程信息SELECT * FROM course WHERE courseid=401;* */// 查询一个数据,使用BeanHandler将记录转换为对象BeanHandler<Course> course = new BeanHandler<Course>(Course.class);String sql = "SELECT * FROM `course` WHERE `courseid`=?;";try {return queryRunner.query(sql, course, courseid);} catch (SQLException e) {e.printStackTrace();}return null;}@Overridepublic List<Course> courseSelectAll() {/*#查看所有课程信息SELECT * FROM course;* */// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Course> courseList = new BeanListHandler<Course>(Course.class);String sql = "SELECT * FROM `course`;";try {return queryRunner.query(sql, courseList);} catch (SQLException e) {e.printStackTrace();}return null;}
}
ScoreDaoImpl实现类
package com.nanchu.dao.impl;import com.nanchu.dao.ScoreDao;
import com.nanchu.entity.Score;
import com.nanchu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:03* @Version 1.0*/
public class ScoreDaoImpl implements ScoreDao {// 创建QueryRunner对象,并传递一个数据源对象private QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());@Overridepublic int scoreInsert(Score score) {return 0;}@Overridepublic int scoreDelete(int studentid) {return 0;}@Overridepublic int scoreUpdate(Score score) {return 0;}// 查看一个学生全部成绩@Overridepublic List<Score> scoreSelectOne(int studentid) {/*#查看指定学生成绩信息
SE      SELECT * FROM score WHERE studentid=301;* */// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Score> scoreList = new BeanListHandler<Score>(Score.class);String sql = "SELECT * FROM `score` WHERE `studentid`=?;";try {return queryRunner.query(sql,scoreList,studentid);} catch (SQLException e) {e.printStackTrace();}return null;}// 查询所有学生所有成绩。@Overridepublic List<Score> scoreSelectAll() {/*#查看所有学生成绩信息SELECT * FROM score;* */// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Score> scoreList = new BeanListHandler<Score>(Score.class);String sql = "SELECT * FROM `score`;";try {return queryRunner.query(sql, scoreList);} catch (SQLException e) {e.printStackTrace();}return null;}// #查看自己指定科目成绩信息@Overridepublic Score selectStudentCourse(int studentid,int courseid){// 查询一个数据,使用BeanHandler将记录转换为对象BeanHandler<Score> sc = new BeanHandler<Score>(Score.class);/*SELECT * FROM score WHERE courseid=401 AND studentid=301;*/String sql = "SELECT * FROM `score` WHERE `studentid`=? AND `courseid`=?;";try {return queryRunner.query(sql, sc, studentid,courseid);} catch (SQLException e) {e.printStackTrace();}return null;}
}
StudentDaoImpl实现类
package com.nanchu.dao.impl;import com.nanchu.dao.StudentDao;
import com.nanchu.entity.Student;
import com.nanchu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:09* @Version 1.0*/
public class StudentDaoImpl implements StudentDao {// 创建QueryRunner对象,并传递一个数据源对象private QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());@Overridepublic int studentInsert(Student student) {/*#添加学生信息
INSERT INTO student(studentid,stname,stsex,stage,clazzid,stpassword) VALUES(311,'学生55','女',14,13,'st008');* */String sql = "INSERT INTO `student`(`studentid`,`stname`,`stsex`,`stage`,`clazzid`,`stpassword`)VALUES(?,?,?,?,?,?);";Object[] args = { student.getStudentid(), student.getStname(),student.getStsex(),student.getStage(),student.getClazzid(),student.getStpassword() };try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic int studentDelete(int studentid) {/*#删除指定学生信息
DELETE FROM student WHERE studentid=311;* */String sql = "DELETE FROM `student` WHERE `studentid` = ?;";try {queryRunner.update("SET FOREIGN_KEY_CHECKS = 0;");int x= queryRunner.update(sql, studentid);queryRunner.update("SET FOREIGN_KEY_CHECKS = 1; ");return x;} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic int studentUpdate(Student student) {/*#修改指定学生信息
UPDATE student SET stname='学生1',stsex='男',stage=15,clazzid=11,stpassword='st001' WHERE studentid = 301;
UPDATE student SET stname='我是学生',stsex='男',stage=15,clazzid=11,stpassword='st001' WHERE studentid = 301;*/String sql = "UPDATE `student` SET `stname` = ?,`stsex`=?,`stage`=? ,`clazzid` = ?,`stpassword`=?  WHERE `studentid`=?;";Object[] args = { student.getStname(),student.getStsex(),student.getStage(),student.getClazzid(),student.getStpassword(),student.getStudentid()};try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic Student studentSelectOne(int studentid) {/*#查看指定学生信息SELECT * FROM student WHERE studentid=301;*/// 查询一个数据,使用BeanHandler将记录转换为对象BeanHandler<Student> student = new BeanHandler<Student>(Student.class);String sql = "SELECT * FROM `student` WHERE `studentid`=?;";try {return queryRunner.query(sql, student, studentid);} catch (SQLException e) {e.printStackTrace();}return null;}@Overridepublic List<Student> studentSelectAll() {/*#查看所有学生信息SELECT * FROM student;*/// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Student> studentList = new BeanListHandler<Student>(Student.class);String sql = "SELECT * FROM `student`;";try {return queryRunner.query(sql, studentList);} catch (SQLException e) {e.printStackTrace();}return null;}
}
TeacherDaoImpl实现类
package com.nanchu.dao.impl;import com.nanchu.dao.TeacherDao;
import com.nanchu.entity.Teacher;
import com.nanchu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:24* @Version 1.0*/
public class TeacherDaoImpl implements TeacherDao {// 创建QueryRunner对象,并传递一个数据源对象private QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());@Overridepublic int teacherInsert(Teacher teacher) {/*#添加老师信息INSERT INTO teacher(teacherid,thname,thage,thsex,clazzid,thpassword)VALUES(207,'老师7',40,'男',13,'8888');*/String sql = "INSERT INTO `teacher`(`teacherid`,`thname`,`thage`,`thsex`,`clazzid`,`thpassword`)VALUES(?,?,?,?,?,?);";Object[] args = {teacher.getTeacherid(),teacher.getThname(),teacher.getThage(),teacher.getThsex(),teacher.getClazzid(),teacher.getThpassword()};try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic int teacherDelete(int teacherid) {/*#删除指定老师信息DELETE FROM teacher WHERE teacherid=207;*/String sql = "DELETE FROM `teacher` WHERE `teacherid` = ?;";try {queryRunner.update("SET FOREIGN_KEY_CHECKS = 0;");int x = queryRunner.update(sql, teacherid);queryRunner.update("SET FOREIGN_KEY_CHECKS = 1;");return x;} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic int teacherUpdate(Teacher teacher) {/* #修改指定老师信息UPDATE teacher SET thname='老师1',thage=30,thsex='男',clazzid=11,thpassword='th001' WHERE teacherid = 201;UPDATE teacher SET thname='老师8',thage=30,thsex='女',clazzid=11,thpassword='th001' WHERE teacherid = 201;*/String sql = "UPDATE `teacher` SET `thname` = ?,`thage`=?,`thsex`=?,`clazzid` = ?,`thpassword`=? WHERE `teacherid`=?;";Object[] args = {teacher.getThname(),teacher.getThage(),teacher.getThsex(),teacher.getClazzid(),teacher.getThpassword(), teacher.getTeacherid()};try {return queryRunner.update(sql, args);} catch (SQLException e) {e.printStackTrace();}return 0;}@Overridepublic Teacher teacherSelectOne(int teacherid) {/*#查看指定老师信息SELECT * FROM teacher WHERE teacherid =201 ;*/// 查询一个数据,使用BeanHandler将记录转换为对象BeanHandler<Teacher> teacher = new BeanHandler<Teacher>(Teacher.class);String sql = "SELECT * FROM `teacher` WHERE `teacherid`=?;";try {return queryRunner.query(sql, teacher, teacherid);} catch (SQLException e) {e.printStackTrace();}return null;}@Overridepublic List<Teacher> teacherSelectAll() {/*#查看所有老师信息SELECT * FROM teacher ;*/// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Teacher> teacherList = new BeanListHandler<Teacher>(Teacher.class);String sql = "SELECT * FROM `teacher`;";try {return queryRunner.query(sql, teacherList);} catch (SQLException e) {e.printStackTrace();}return null;}
}
QueryOtherWayImpl实现类
package com.nanchu.dao.impl;import com.nanchu.dao.QueryOtherWay;
import com.nanchu.entity.Clazz;
import com.nanchu.entity.Score;
import com.nanchu.entity.Student;
import com.nanchu.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;import java.sql.SQLException;
import java.util.List;/*** @Author 南初* @Create 2024/3/11 9:14* @Version 1.0*/
public class QueryOtherWayImpl implements QueryOtherWay{// 创建QueryRunner对象,并传递一个数据源对象private QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());/*** #查看自己班级所有学生信息** @param clazzid*/@Overridepublic List<Student> allStudentClazz(int clazzid) {// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Student> studentList = new BeanListHandler<Student>(Student.class);//SELECT *//FROM student//WHERE clazzid=11;String sql="SELECT * FROM student WHERE  `clazzid`=?;";try {return queryRunner.query(sql,studentList,clazzid);} catch (SQLException e) {e.printStackTrace();}return null;}/*** 查看自己班级指定学生信息** @param studentid*/@Overridepublic List<Student> OneStudentClazz(int clazzid,int studentid) {// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Student> studentList = new BeanListHandler<Student>(Student.class);//SELECT *//FROM student//WHERE  clazzid = 11 AND studentid=301;String sql="SELECT * FROM student WHERE  `clazzid`=? AND `studentid`=?;";try {return queryRunner.query(sql,studentList,clazzid,studentid);} catch (SQLException e) {e.printStackTrace();}return null;}/*** #查看所有班级指定科目成绩信息** @param courseid*/@Overridepublic List<Score> allClazzOneCourseScore(int courseid) {// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Score> scoreList = new BeanListHandler<Score>(Score.class);/*SELECT b.`studentid`,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND b.`courseid`=401;* */String sql="SELECT b.`studentid`,b.`courseid`,b.`grade` FROM `clazz` a ,`score` b,`student` c WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND b.`courseid`=?;";try {return queryRunner.query(sql,scoreList,courseid);} catch (SQLException e) {e.printStackTrace();}return null;}/*** 自己班级所有学生所有科目成绩信息** @param clazzid* @return*/@Overridepublic List<Score> allStudentAllCourseScore(int clazzid) {// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Score> scoreList = new BeanListHandler<Score>(Score.class);String sql="SELECT b.`studentid`,b.`courseid`,b.`grade` FROM `student` a ,`score` b,`course` c WHERE a.`studentid` = b.`studentid` AND b.`courseid` = c.`courseid` AND a.`clazzid`=?;";try {return queryRunner.query(sql,scoreList,clazzid);} catch (SQLException e) {e.printStackTrace();}return null;}/*** 自己班级所有学生指定科目成绩信息** @param clazzid* @param courseid* @return*/@Overridepublic List<Score> allStudentOneCourseScore(int clazzid, int courseid) {// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Score> scoreList = new BeanListHandler<Score>(Score.class);/** SELECT b.studentid,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND b.`courseid`=401 AND a.`clazzid`=11 ;
*/String sql="SELECT b.`studentid`,b.`courseid`,b.`grade` FROM `clazz` a ,`score` b,`student` c WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND a.`clazzid`=? AND b.`courseid`=?;";try {return queryRunner.query(sql,scoreList,clazzid,courseid);} catch (SQLException e) {e.printStackTrace();}return null;}/*** 自己班级指定学生所有科目成绩信息** @param clazzid* @param studentid* @return*/@Overridepublic List<Score> oneStudentAllCourseScore(int clazzid, int studentid) {// 查询一个数据,使用BeanHandler将记录转换为对象/** SELECT b.studentid,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND c.`studentid`=301 AND a.`clazzid`=11 ;* */BeanListHandler<Score> scoreList = new BeanListHandler<Score>(Score.class);String sql="SELECT b.`studentid`,b.`courseid`,b.`grade` FROM `clazz` a ,`score` b,`student` c WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND  a.`clazzid`= ? AND c.`studentid`=?;";try {return queryRunner.query(sql,scoreList,clazzid,studentid);} catch (SQLException e) {e.printStackTrace();}return null;}/*** 自己班级指定学生指定科目成绩信息** @param clazzid* @param studentid* @param courseid*/@Overridepublic List<Score> oneStudentOneCourseScore(int clazzid, int studentid, int courseid) {// 查询一个数据,使用BeanHandler将记录转换为对象BeanListHandler<Score> scoreList = new BeanListHandler<Score>(Score.class);
/*
* SELECT b.studentid,b.`courseid`,b.`grade`
FROM clazz a,score b ,student c
WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND  a.`clazzid`=11   AND  c.`studentid`=301 AND b.`courseid`=401 ;
* */String sql="SELECT b.`studentid`,b.`courseid`,b.`grade` FROM `clazz` a ,`score` b,`student` c WHERE a.`clazzid`=c.`clazzid` AND b.`studentid`=c.`studentid` AND  a.`clazzid`= ?   AND  c.`studentid`=? AND b.`courseid`=? ;";try {return queryRunner.query(sql,scoreList,clazzid,studentid,courseid);} catch (SQLException e) {e.printStackTrace();}return null;}
}

3.4.3service层(com.nanchu.service)

AccountService接口
package com.nanchu.service;import com.nanchu.entity.Account;/*** @Author 南初* @Create 2024/3/10 12:13* @Version 1.0*/
public interface AccountService {// 查询账号信息//查询单个Account accountSelectOneAccount(int atid);}
ClazzService接口
package com.nanchu.service;import com.nanchu.entity.Clazz;import java.util.List;/*** @Author 南初* @Create 2024/3/10 12:54* @Version 1.0*/
public interface ClazzService {/*** 增加一个班级* *///增加int addClazz(Clazz clazz);/*** 删除一个班级* *///删除int deleteClazz(int clazzid);/*** 修改一个班级信息* *///修改int updateClazz(Clazz clazz);/*** 查询一个班级信息* *///查询单个Clazz selectOneClazz(int clazzid);/*** 查询所有班级信息* *///查询所有List<Clazz> selectAllClazz();
}
CourseService接口
package com.nanchu.service;import com.nanchu.entity.Course;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:37* @Version 1.0*/
public interface CourseService {/*** 增加一个课程* *///增加int addCourse(Course course);/*** 删除一个课程* *///删除int deleteCourse(int courseid);/*** 修改一个课程信息* *///修改int updateCourse(Course course);/*** 查询一个课程信息* *///查询单个Course selectOneCourse(int courseid);/*** 查询所有课程信息* *///查询所有List<Course> selectAllCourse();
}
ScoreService接口
package com.nanchu.service;import com.nanchu.entity.Score;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:37* @Version 1.0*/
public interface ScoreService {/*** 查询一个成绩信息* *///查询单个List<Score> selectOneScore(int studentid);/*** 查询所有成绩信息* *///查询所有List<Score> selectAllScore();// 查询自己指定科目成绩Score selectStudentCourse(int studentid,int courseid);
}
StudentService接口
package com.nanchu.service;import com.nanchu.entity.Clazz;
import com.nanchu.entity.Course;
import com.nanchu.entity.Student;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:37* @Version 1.0*/
public interface StudentService {/*** 增加一个学生* *///增加int addStudent(Student student);/*** 删除一个学生* *///删除int deleteStudent(int studentid);/*** 修改一个学生信息* *///修改int updateStudent(Student student);/*** 查询一个学生信息* *///查询单个Student selectOneStudent(int studentid);/*** 查询所有学生信息* *///查询所有List<Student> selectAllStudent();
}
TeacherService接口
package com.nanchu.service;import com.nanchu.entity.Clazz;
import com.nanchu.entity.Student;
import com.nanchu.entity.Teacher;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:38* @Version 1.0*/
public interface TeacherService {/*** 增加一个老师* *///增加int addTeacher(Teacher teacher);/*** 删除一个老师* *///删除int deleteTeacher(int teacherid);/*** 修改一个老师信息* *///修改int updateTeacher(Teacher teacher);/*** 查询一个老师信息* *///查询单个Teacher selectOneTeacher(int teacherid);/*** 查询所有老师信息* *///查询所有List<Teacher> selectAllTeacher();
}

3.4.4service.impl(com.nanchu.service.impl)

AccountServiceImpl实现类
package com.nanchu.service.impl;import com.nanchu.dao.AccountDao;
import com.nanchu.dao.impl.AccountDaoImpl;
import com.nanchu.entity.Account;
import com.nanchu.service.AccountService;/*** @Author 南初* @Create 2024/3/10 12:14* @Version 1.0*/
public class AccountServiceImpl implements AccountService {AccountDao accountDao = new AccountDaoImpl();@Overridepublic Account accountSelectOneAccount(int atid) {Account account =accountDao.accountSelectOne(atid);if(account!=null){return account;}else{System.out.println("没有你要查找管理员账号,查找失败");}return null;}
}
ClazzServiceImpl实现类
package com.nanchu.service.impl;import com.nanchu.dao.ClazzDao;
import com.nanchu.dao.impl.ClazzDaoImpl;
import com.nanchu.entity.Clazz;
import com.nanchu.service.ClazzService;import java.util.List;/*** @Author 南初* @Create 2024/3/10 12:58* @Version 1.0*/
public class ClazzServiceImpl implements ClazzService {ClazzDao clazzDao = new ClazzDaoImpl();/*** 增加一个班级* @param clazz*/@Overridepublic int addClazz(Clazz clazz) {// 查询添加的班级是否存在Clazz cl = clazzDao.clazzSelectOne(clazz.getClazzid());if (cl == null) {return clazzDao.clazzInsert(clazz);} else {System.out.println("班级已经存在,不能重复添加");}return 0;}/*** 删除一个班级** @param clazzid*/@Overridepublic int deleteClazz(int clazzid) {// 查询添加的班级是否存在Clazz cl = clazzDao.clazzSelectOne(clazzid);if (cl != null) {return clazzDao.clazzDelete(clazzid);} else {System.out.println("班级不存在,不能删除");}return 0;}/*** 修改一个班级信息** @param clazz*/@Overridepublic int updateClazz(Clazz clazz) {// 查询添加的商品是否存在Clazz cl = clazzDao.clazzSelectOne(clazz.getClazzid());if (cl!= null) {return clazzDao.clazzUpdate(clazz);} else {System.out.println("班级不存在,不能修改");}return 0;}/*** 查询一个班级信息** @param clazzid*/@Overridepublic Clazz selectOneClazz(int clazzid) {Clazz clazz = clazzDao.clazzSelectOne(clazzid);if(clazz!=null){return clazz;}else{System.out.println("没有你要查找产品,查找失败");}return null;}/*** 查询所有班级信息*/@Overridepublic List<Clazz> selectAllClazz() {List<Clazz> clazzList = clazzDao.clazzSelectAll();if(clazzList.size()!=0){return clazzList;}else{System.out.println("数据库为空,没有班级信息");}return null;}
}
CourseServiceImpl实现类
package com.nanchu.service.impl;import com.nanchu.dao.CourseDao;
import com.nanchu.dao.impl.CourseDaoImpl;
import com.nanchu.entity.Clazz;
import com.nanchu.entity.Course;
import com.nanchu.service.CourseService;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:52* @Version 1.0*/
public class CourseServiceImpl implements CourseService {CourseDao courseDao = new CourseDaoImpl();/*** 增加一个课程** @param course*/@Overridepublic int addCourse(Course course) {// 查询添加的课程是否存在Course cs = courseDao.courseSelectOne(course.getCourseid());if (cs == null) {return courseDao.courseInsert(course);} else {System.out.println("课程已经存在,不能重复添加");}return 0;}/*** 删除一个课程** @param courseid*/@Overridepublic int deleteCourse(int courseid) {// 查询添加的课程是否存在Course cs = courseDao.courseSelectOne(courseid);if (cs != null) {return courseDao.courseDelete(courseid);} else {System.out.println("课程不存在,不能删除");}return 0;}/*** 修改一个课程信息** @param course*/@Overridepublic int updateCourse(Course course) {// 查询添加的课程是否存在Course cs = courseDao.courseSelectOne(course.getCourseid());if (cs!= null) {return courseDao.courseUpdate(course);} else {System.out.println("课程不存在,不能修改");}return 0;}/*** 查询一个课程信息** @param courseid*/@Overridepublic Course selectOneCourse(int courseid) {Course cs = courseDao.courseSelectOne(courseid);if(cs!=null){return cs;}else{System.out.println("没有你要查找课程,查找失败");}return null;}/*** 查询所有课程信息*/@Overridepublic List<Course> selectAllCourse() {List<Course> courseList = courseDao.courseSelectAll();if(courseList.size()!=0){return courseList;}else{System.out.println("数据库为空,没有课程");}return null;}
}
ScoreServiceImpl实现类
package com.nanchu.service.impl;import com.nanchu.dao.ScoreDao;
import com.nanchu.dao.impl.ScoreDaoImpl;
import com.nanchu.entity.Clazz;
import com.nanchu.entity.Score;
import com.nanchu.service.ScoreService;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:53* @Version 1.0*/
public class ScoreServiceImpl implements ScoreService {ScoreDao scoreDao = new ScoreDaoImpl();/*** 查询一个成绩信息** @param studentid*/@Overridepublic List<Score>  selectOneScore(int studentid) {List<Score> scoreList = scoreDao.scoreSelectOne(studentid);if(scoreList.size()!=0){return scoreList;}else{System.out.println("数据库为空,没有成绩");}return null;}/*** 查询所有成绩信息*/@Overridepublic List<Score> selectAllScore() {List<Score> scoreList = scoreDao.scoreSelectAll();if(scoreList.size()!=0){return scoreList;}else{System.out.println("数据库为空,没有成绩");}return null;}/*** 查询自己指定科目成绩* @param studentid* @param courseid* @return*/@Overridepublic Score selectStudentCourse(int studentid, int courseid) {Score score = scoreDao.selectStudentCourse(studentid, courseid);if(score!=null){return score;}else{System.out.println("没有你要查找成绩,查找失败");}return null;}
}
StudentServiceImpl实现类
package com.nanchu.service.impl;import com.nanchu.dao.StudentDao;
import com.nanchu.dao.impl.StudentDaoImpl;
import com.nanchu.entity.Student;
import com.nanchu.service.StudentService;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:53* @Version 1.0*/
public class StudentServiceImpl implements StudentService {StudentDao studentDao = new StudentDaoImpl();/*** 增加一个学生** @param student*/@Overridepublic int addStudent(Student student) {// 查询添加的学生是否存在Student st = studentDao.studentSelectOne(student.getStudentid());if (st == null) {return studentDao.studentInsert(student);} else {System.out.println("该学生已经存在,不能重复添加");}return 0;}/*** 删除一个学生** @param studentid*/@Overridepublic int deleteStudent(int studentid) {// 查询添加的商品是否存在Student student = studentDao.studentSelectOne(studentid);if (student != null) {return studentDao.studentDelete(studentid);} else {System.out.println("学生不存在,不能删除");}return 0;}/*** 修改一个学生信息** @param student*/@Overridepublic int updateStudent(Student student) {// 查询添加的商品是否存在Student st = studentDao.studentSelectOne(student.getStudentid());if (st!= null) {return studentDao.studentUpdate(student);} else {System.out.println("学生不存在,不能修改");}return 0;}/*** 查询一个学生信息** @param studentid*/@Overridepublic Student selectOneStudent(int studentid) {Student student = studentDao.studentSelectOne(studentid);if(student!=null){return student;}else{System.out.println("没有你要查找学生信息,查找失败");}return null;}/*** 查询所有学生信息*/@Overridepublic List<Student> selectAllStudent() {List<Student> studentList = studentDao.studentSelectAll();if(studentList.size()!=0){return studentList;}else{System.out.println("学生表为空,没有学生信息");}return null;}
}
TeacherServiceImpl实现类
package com.nanchu.service.impl;import com.nanchu.dao.TeacherDao;
import com.nanchu.dao.impl.TeacherDaoImpl;
import com.nanchu.entity.Teacher;
import com.nanchu.service.TeacherService;import java.util.List;/*** @Author 南初* @Create 2024/3/10 14:53* @Version 1.0*/
public class TeacherServiceImpl implements TeacherService {TeacherDao teacherDao = new TeacherDaoImpl();/*** 增加一个老师** @param teacher*/@Overridepublic int addTeacher(Teacher teacher) {// 查询添加的商品是否存在Teacher th = teacherDao.teacherSelectOne(teacher.getTeacherid());if (th == null) {return teacherDao.teacherInsert(teacher);} else {System.out.println("老师已经存在,不能重复添加");}return 0;}/*** 删除一个老师** @param teacherid*/@Overridepublic int deleteTeacher(int teacherid) {// 查询添加的商品是否存在Teacher teacher = teacherDao.teacherSelectOne(teacherid);if (teacher != null) {return teacherDao.teacherDelete(teacherid);} else {System.out.println("老师不存在,不能删除");}return 0;}/*** 修改一个老师信息** @param teacher*/@Overridepublic int updateTeacher(Teacher teacher) {// 查询添加的商品是否存在Teacher th = teacherDao.teacherSelectOne(teacher.getTeacherid());if (th!= null) {return teacherDao.teacherUpdate(teacher);} else {System.out.println("老师信息不存在,不能修改");}return 0;}/*** 查询一个老师信息** @param teacherid*/@Overridepublic Teacher selectOneTeacher(int teacherid) {Teacher teacher = teacherDao.teacherSelectOne(teacherid);if(teacher!=null){return teacher;}else{System.out.println("没有你要查找老师信息,查找失败");}return null;}/*** 查询所有老师信息*/@Overridepublic List<Teacher> selectAllTeacher() {List<Teacher> teacherList = teacherDao.teacherSelectAll();if(teacherList.size()!=0){return teacherList;}else{System.out.println("老师表为空,没有老师信息");}return null;}
}

3.4.5entity实体类

Account实体类
package com.nanchu.entity;public class Account {private int atid;private String atname;private String atpassword;public Account(){}public Account(String atname,String atpassword){this.atname=atname;this.atpassword=atpassword;}public Account(int atid,String atname,String atpassword){this.atid=atid;this.atname=atname;this.atpassword=atpassword;}public void setAtid(int atid){this.atid=atid;}public int getAtid(){return atid;}public void setAtname(String atname){this.atname=atname;}public String getAtname(){return atname;}public void setAtpassword(String atpassword){this.atpassword=atpassword;}public String getAtpassword(){return atpassword;}@Overridepublic String toString() {return "Account{"+"atid="+atid+",atname="+atname+",atpassword="+atpassword+"}";}
}
Clazz实体类
package com.nanchu.entity;public class Clazz {private int clazzid;private String clname;public Clazz(){}public Clazz(String clname){this.clname=clname;}public Clazz(int clazzid,String clname){this.clazzid=clazzid;this.clname=clname;}public void setClazzid(int clazzid){this.clazzid=clazzid;}public int getClazzid(){return clazzid;}public void setClname(String clname){this.clname=clname;}public String getClname(){return clname;}@Overridepublic String toString() {return "Clazz{"+"clazzid="+clazzid+",clname="+clname+"}";}
}
Course实体类
package com.nanchu.entity;public class Course {private int courseid;private String csname;private int teacherid;public Course(){}public Course(String csname,int teacherid){this.csname=csname;this.teacherid=teacherid;}public Course(int courseid,String csname,int teacherid){this.courseid=courseid;this.csname=csname;this.teacherid=teacherid;}public void setCourseid(int courseid){this.courseid=courseid;}public int getCourseid(){return courseid;}public void setCsname(String csname){this.csname=csname;}public String getCsname(){return csname;}public void setTeacherid(int teacherid){this.teacherid=teacherid;}public int getTeacherid(){return teacherid;}@Overridepublic String toString() {return "Course{"+"courseid="+courseid+",csname="+csname+",teacherid="+teacherid+"}";}
}
Score实体类
package com.nanchu.entity;public class Score {private int studentid;private int courseid;private int grade;public Score(){}public Score(int courseid,int grade){this.courseid=courseid;this.grade=grade;}public Score(int studentid,int courseid,int grade){this.studentid=studentid;this.courseid=courseid;this.grade=grade;}public void setStudentid(int studentid){this.studentid=studentid;}public int getStudentid(){return studentid;}public void setCourseid(int courseid){this.courseid=courseid;}public int getCourseid(){return courseid;}public void setGrade(int grade){this.grade=grade;}public int getGrade(){return grade;}@Overridepublic String toString() {return "Score{"+"studentid="+studentid+",courseid="+courseid+",grade="+grade+"}";}
}
Student实体类
package com.nanchu.entity;public class Student {private int studentid;private String stname;private String stsex;private int stage;private int clazzid;private String stpassword;public Student(){}public Student(String stname,String stsex,int stage,int clazzid,String stpassword){this.stname=stname;this.stsex=stsex;this.stage=stage;this.clazzid=clazzid;this.stpassword=stpassword;}public Student(int studentid,String stname,String stsex,int stage,int clazzid,String stpassword){this.studentid=studentid;this.stname=stname;this.stsex=stsex;this.stage=stage;this.clazzid=clazzid;this.stpassword=stpassword;}public void setStudentid(int studentid){this.studentid=studentid;}public int getStudentid(){return studentid;}public void setStname(String stname){this.stname=stname;}public String getStname(){return stname;}public void setStsex(String stsex){this.stsex=stsex;}public String getStsex(){return stsex;}public void setStage(int stage){this.stage=stage;}public int getStage(){return stage;}public void setClazzid(int clazzid){this.clazzid=clazzid;}public int getClazzid(){return clazzid;}public void setStpassword(String stpassword){this.stpassword=stpassword;}public String getStpassword(){return stpassword;}@Overridepublic String toString() {return "Student{"+"studentid="+studentid+",stname="+stname+",stsex="+stsex+",stage="+stage+",clazzid="+clazzid+",stpassword="+stpassword+"}";}
}
Teacher实体类
package com.nanchu.entity;public class Teacher {private int teacherid;private String thname;private int thage;private String thsex;private int clazzid;private String thpassword;public Teacher(){}public Teacher(String thname,int thage,String thsex,int clazzid,String thpassword){this.thname=thname;this.thage=thage;this.thsex=thsex;this.clazzid=clazzid;this.thpassword=thpassword;}public Teacher(int teacherid,String thname,int thage,String thsex,int clazzid,String thpassword){this.teacherid=teacherid;this.thname=thname;this.thage=thage;this.thsex=thsex;this.clazzid=clazzid;this.thpassword=thpassword;}public void setTeacherid(int teacherid){this.teacherid=teacherid;}public int getTeacherid(){return teacherid;}public void setThname(String thname){this.thname=thname;}public String getThname(){return thname;}public void setThage(int thage){this.thage=thage;}public int getThage(){return thage;}public void setThsex(String thsex){this.thsex=thsex;}public String getThsex(){return thsex;}public void setClazzid(int clazzid){this.clazzid=clazzid;}public int getClazzid(){return clazzid;}public void setThpassword(String thpassword){this.thpassword=thpassword;}public String getThpassword(){return thpassword;}@Overridepublic String toString() {return "Teacher{"+"teacherid="+teacherid+",thname="+thname+",thage="+thage+",thsex="+thsex+",clazzid="+clazzid+",thpassword="+thpassword+"}";}
}

3.4.6utils工具类

PageUtils选择功能页面
package com.nanchu.utils;/*** @Author 南初* @Create 2024/3/10 17:17* @Version 1.0*/
public class PageUtils {public void page1(){System.out.println("----------------登录界面----------------");System.out.println("               1、管理员登录");System.out.println("               2、教师登录");System.out.println("               3、学生登录");System.out.println("               0、退出");}public void page2(){System.out.println("****************欢迎进入管理员账户页面****************");System.out.println("               1、查看所有班级信息");System.out.println("               2、查看指定班级信息");System.out.println("               3、修改指定班级信息");System.out.println("               4、添加班级信息");System.out.println("               5、删除指定班级信息");System.out.println("---------------------------------");System.out.println("               6、查看所有课程信息");System.out.println("               7、查看指定课程信息");System.out.println("               8、修改指定课程信息");System.out.println("               9、添加课程信息");System.out.println("               10、删除指定课程信息");System.out.println("---------------------------------");System.out.println("               11、查看所有老师信息");System.out.println("               12、查看指定老师信息");System.out.println("               13、修改指定老师信息");System.out.println("               14、删除指定老师信息");System.out.println("               15、添加老师信息");System.out.println("---------------------------------");System.out.println("               16、查看所有学生信息");System.out.println("               17、查看指定学生信息");System.out.println("               18、添加学生信息");System.out.println("               19、修改指定学生信息");System.out.println("               20、删除指定学生信息");System.out.println("---------------------------------");System.out.println("               21、查看所有学生成绩信息");System.out.println("               22、查看指定学生成绩信息");System.out.println("               23、查看指定班级所有学生成绩信息");System.out.println("               24、查看所有班级指定科目成绩信息");System.out.println("               25、查看指定班级指定科目成绩信息");System.out.println("               0、退出");System.out.println("---------------------------------");}public void page3(){System.out.println("**************欢迎进入老师账户页面****************");System.out.println("               1、 查看自己的信息");System.out.println("               2、 修改自己的信息");System.out.println("               3、 删除自己的信息");System.out.println("-----------------------------------------------");System.out.println("               4、 查看自己班级所有学生信息");System.out.println("               5、 查看自己班级指定学生信息");System.out.println("               6、 添加自己班级学生信息");System.out.println("               7、 修改自己班级指定学生信息");System.out.println("               8、 删除自己班级指定学生信息");System.out.println("------------------------------------------------");System.out.println("               9、 查看自己班级所有学生所有科目成绩信息");System.out.println("               10、查看自己班级所有学生指定科目成绩信息");System.out.println("               11、查看自己班级指定学生所有科目成绩信息");System.out.println("               12、查看自己班级指定学生指定科目成绩信息");System.out.println("               0、退出");System.out.println("--------------------------------------------------");}public void page4(){System.out.println("***************欢迎进入学生账户页面****************");System.out.println("               1、查看自己的信息");System.out.println("               2、修改自己的信息");System.out.println("-----------------------------------------------");System.out.println("               3、删除自己的信息");System.out.println("               4、查看自己所有科目成绩信息");System.out.println("               5、查看自己指定科目成绩信息");System.out.println("-----------------------------------------------");System.out.println("               6、查看自己班级所有学生所有科目成绩信息");System.out.println("               7、查看自己班级所有学生指定科目成绩信息");System.out.println("               8、查看自己班级指定学生所有科目成绩信息");System.out.println("               9、查看自己班级指定学生指定科目成绩信息");System.out.println("               0、退出");System.out.println("------------------------------------------------");}}
LoginUtils三种账号登录验证
package com.nanchu.utils;import com.nanchu.entity.Account;
import com.nanchu.entity.Student;
import com.nanchu.entity.Teacher;
import com.nanchu.service.AccountService;
import com.nanchu.service.StudentService;
import com.nanchu.service.TeacherService;
import com.nanchu.service.impl.AccountServiceImpl;
import com.nanchu.service.impl.StudentServiceImpl;
import com.nanchu.service.impl.TeacherServiceImpl;import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 15:44* @Version 1.0*/
public class LoginUtils {Scanner scan = new Scanner(System.in);public int loginCheck1() {AccountService accountService = new AccountServiceImpl();//  管理员登录验证     手机号码+密码System.out.println("\n---请输入你的验证信息---");System.out.print("\n请输入管理员账号:");int accountId = scan.nextInt();System.out.print("\n请输入账号密码:");String accountPassword = scan.next();Account account =null;account  = accountService.accountSelectOneAccount(accountId);while(true){if(account == null){System.out.println("输入账号信息错误,请重新输入信息!");System.out.print("\n请输入管理员账号:");accountId = scan.nextInt();System.out.print("\n请输入账号密码:");accountPassword = scan.next();account  = accountService.accountSelectOneAccount(accountId);}else if( accountId == account.getAtid() && accountPassword.equals(account.getAtpassword())){break;}else{System.out.println("输入账号信息错误,请重新输入信息!");System.out.print("\n请输入管理员账号:");accountId = scan.nextInt();System.out.print("\n请输入账号密码:");accountPassword = scan.next();account  = accountService.accountSelectOneAccount(accountId);}}System.out.println("登录成功!");return accountId;}public int loginCheck2() {TeacherService teacherService = new TeacherServiceImpl();//  教师登录验证     手机号码+密码System.out.println("\n---请输入你的验证信息---");System.out.print("\n请输入教师账号:");int teacherId = scan.nextInt();System.out.print("\n请输入账号密码:");String teacherPassword = scan.next();Teacher teacher =null;teacher = teacherService.selectOneTeacher(teacherId);while(true){if(teacher == null){System.out.println("输入账号信息错误,请重新输入信息!");System.out.print("\n请输入教师账号:");teacherId = scan.nextInt();System.out.print("\n请输入账号密码:");teacherPassword = scan.next();teacher = teacherService.selectOneTeacher(teacherId);}else if( teacherId == teacher.getTeacherid() && teacherPassword.equals(teacher.getThpassword())){break;}else {System.out.println("输入账号信息错误,请重新输入信息!");System.out.print("\n请输入教师账号:");teacherId = scan.nextInt();System.out.print("\n请输入账号密码:");teacherPassword = scan.next();teacher = teacherService.selectOneTeacher(teacherId);}}System.out.println("登录成功!");return teacherId;}public int loginCheck3() {StudentService studentService = new StudentServiceImpl();//  管理员登录验证     手机号码+密码System.out.println("\n---请输入你的验证信息---");System.out.print("\n请输入学生账号:");int studentId = scan.nextInt();System.out.print("\n请输入账号密码:");String studentPassword = scan.next();Student student =null;student = studentService.selectOneStudent(studentId);while(true){if(student == null){System.out.println("输入账号信息错误,请重新输入信息!");System.out.print("\n请输入学生账号:");studentId = scan.nextInt();System.out.print("\n请输入账号密码:");studentPassword = scan.next();student = studentService.selectOneStudent(studentId);}else if( studentId == student.getStudentid() && studentPassword.equals(student.getStpassword())){break;}else {System.out.println("输入账号信息错误,请重新输入信息!");System.out.print("\n请输入学生账号:");studentId = scan.nextInt();System.out.print("\n请输入账号密码:");studentPassword = scan.next();student = studentService.selectOneStudent(studentId);}}System.out.println("登录成功!");return studentId;}
}
DBUtils:Druid连接池的连接
package com.nanchu.utils;import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;/*** @Author 南初* @Create 2024/3/9 21:55* @Version 1.0*/
public class DBUtils {// 声明一个连接池对象private static DruidDataSource druidDataSource;static {// 实例化配置文件对象Properties properties = new Properties();try {// 加载配置文件内容InputStream is = DBUtils.class.getResourceAsStream("/database.properties");properties.load(is);// 创建连接池druidDataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);} catch (IOException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();}}//返回一个数据源public static DataSource getDataSource(){return druidDataSource;}
}
ClazzFunctionUtils:Clazz班级的相关操作直接在这里被封装成为一个方法直接调用即可
package com.nanchu.utils;import com.nanchu.entity.Clazz;
import com.nanchu.service.ClazzService;
import com.nanchu.service.impl.ClazzServiceImpl;import java.util.List;
import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 20:04* @Version 1.0*/
public class ClazzFunctionUtils {Scanner scan = new Scanner(System.in);// 增加班级public void addOneClazz() {//创建ClazzService引用,指向ClazzServiceImpl实现类ClazzService clazzService = new ClazzServiceImpl();//增加班级System.out.println("请输入要增加的班级编号:");int clazzid = scan.nextInt();System.out.println("请输入要增加的班级名称:");String clazzname = scan.next();Clazz clazz = new Clazz(clazzid,clazzname);int result = clazzService.addClazz(clazz);String str = result==1?"班级添加成功":"班级添加失败";System.out.println(str);}// 修改班级信息public void alterClazzInfo() {//创建ClazzService引用,指向ClazzServiceImpl实现类ClazzService clazzService = new ClazzServiceImpl();//修改班级System.out.println("请输入要修改的班级编号:");int clazzid = scan.nextInt();System.out.println("请输入要修改的班级名称:");String clazzname = scan.next();Clazz clazz = new Clazz(clazzid,clazzname);int result = clazzService.updateClazz(clazz);String str = result == 1 ? "修改成功" : "修改失败";System.out.println(str);}// 删除班级public void delectClazz() {//创建ClazzService引用,指向ClazzServiceImpl实现类ClazzService clazzService = new ClazzServiceImpl();//删除班级System.out.println("请输入要删除的班级编号:");int clazzid = scan.nextInt();int result = clazzService.deleteClazz(clazzid);String str = result == 1 ? "删除成功" : "删除失败";System.out.println(str);}//查询一个班级信息public void lookOneClazz() {//创建ClazzService引用,指向ClazzServiceImpl实现类ClazzService clazzService = new ClazzServiceImpl();//查询班级System.out.println("请输入要查询的班级编号:");int clazzid = scan.nextInt();Clazz clazz = clazzService.selectOneClazz(clazzid);if (clazz != null) {System.out.println(clazz);} else {System.out.println("你要查询的班级不存在");}}//查询所有班级信息public void lookAllClazz() {//创建ClazzService引用,指向ClazzServiceImpl实现类ClazzService clazzService = new ClazzServiceImpl();List<Clazz> clazzList = clazzService.selectAllClazz();for (int i = 0; i < clazzList.size(); i++) {System.out.println(clazzList.get(i));}}
}
CourseFunctionUtils:Course课程的相关操作直接在这里被封装成为一个方法直接调用即可
package com.nanchu.utils;import com.nanchu.entity.Course;
import com.nanchu.service.CourseService;
import com.nanchu.service.impl.CourseServiceImpl;import java.util.List;
import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 20:48* @Version 1.0*/
public class CourseFunctionUtils {Scanner scan = new Scanner(System.in);//增加课程public void addCourseInfo(){//创建CourseService引用,指向CourseServiceImpl实现类CourseService courseService = new CourseServiceImpl();System.out.println("请输入要增加课程的编号:");int courseid = scan.nextInt();System.out.println("请输入要增加课程的名称:");String name = scan.next();System.out.println("请输入要增加此课程所带教师编号:");int teacherid = scan.nextInt();Course course = new Course(courseid,name,teacherid);int result = courseService.addCourse(course);String str = result==1?"课程添加成功":"课程添加失败";System.out.println(str);}//修改课程public void alertCourseInfo(){//创建CourseService引用,指向CourseServiceImpl实现类CourseService courseService = new CourseServiceImpl();System.out.println("请输入要修改课程的编号:");int courseid = scan.nextInt();System.out.println("请输入要修改课程的名称:");String name = scan.next();System.out.println("请输入要修改此课程所带教师编号:");int teacherid = scan.nextInt();Course course = new Course(courseid,name,teacherid);int result = courseService.updateCourse(course);String str = result == 1 ? "修改成功" : "修改失败";System.out.println(str);}//删除课程public void delectCourseInfo(){//创建CourseService引用,指向CourseServiceImpl实现类CourseService courseService = new CourseServiceImpl();System.out.println("请输入要删除课程的编号:");int courseid = scan.nextInt();int result = courseService.deleteCourse(courseid);String str = result == 1 ? "删除成功" : "删除失败";System.out.println(str);}//查询一个课程public void lookOneCourse(){//创建CourseService引用,指向CourseServiceImpl实现类CourseService courseService = new CourseServiceImpl();System.out.println("请输入要查询课程的编号:");int courseid = scan.nextInt();Course course = courseService.selectOneCourse(courseid);if (course != null) {System.out.println(course);} else {System.out.println("你要查询的课程不存在");}}//查询所有课程public void lookAllCourse(){//创建CourseService引用,指向CourseServiceImpl实现类CourseService courseService = new CourseServiceImpl();List<Course> courseList = courseService.selectAllCourse();for (int i = 0; i < courseList.size(); i++) {System.out.println(courseList.get(i));}}
}
ScoreFunctionUtils:Score课程分数的相关操作直接在这里被封装成为一个方法直接调用即可
package com.nanchu.utils;import com.nanchu.entity.Score;
import com.nanchu.service.ScoreService;
import com.nanchu.service.impl.ScoreServiceImpl;import java.util.List;
import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 21:03* @Version 1.0*/
public class ScoreFunctionUtils {Scanner scan = new Scanner(System.in);// 查询一位同学成绩public void lookScoreOneStudent(int studentid){// 创建ProductService引用,指向ProductServiceImpl实现类ScoreService scoreService = new ScoreServiceImpl();List<Score> scoreList= scoreService.selectOneScore(studentid);for (int i = 0; i < scoreList.size(); i++) {System.out.println(scoreList.get(i));}}//查询自己指定科目成绩public void lookScoreOneStudent(int studentid, int courseid){// 创建ProductService引用,指向ProductServiceImpl实现类ScoreService scoreService = new ScoreServiceImpl();Score score = scoreService.selectStudentCourse(studentid, courseid);if (score != null) {System.out.println(score);} else {System.out.println("你要查询的成绩不存在");}}// 查询所有同学成绩public void lookScoreAllStudent(){// 创建ProductService引用,指向ProductServiceImpl实现类ScoreService scoreService = new ScoreServiceImpl();List<Score> scoreList = scoreService.selectAllScore();for (int i = 0; i < scoreList.size(); i++) {System.out.println(scoreList.get(i));}}}
StudentFunctionUtils:Student学生的相关操作直接在这里被封装成为一个方法直接调用即可
package com.nanchu.utils;import com.nanchu.entity.Student;
import com.nanchu.service.StudentService;
import com.nanchu.service.impl.StudentServiceImpl;import java.util.List;
import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 19:11* @Version 1.0*/
public class StudentFunctionUtils {Scanner scan = new Scanner(System.in);// 查看学生的信息public void lookOwnInfo(int studentid){// 创建StudentService引用,指向StudentServiceImpl实现类StudentService studentService = new StudentServiceImpl();Student student = studentService.selectOneStudent(studentid);if (student != null) {System.out.println(student);} else {System.out.println("你要查询的学生信息不存在");}}// 查看学生的信息public Student returnOneStudent(int studentid){// 创建StudentService引用,指向StudentServiceImpl实现类StudentService studentService = new StudentServiceImpl();Student student = studentService.selectOneStudent(studentid);if (student != null) {return student;} else {System.out.println("你要查询的学生信息不存在");}return null;}// 查看所有学生的信息public void lookAllInfo(){// 创建StudentService引用,指向StudentServiceImpl实现类StudentService studentService = new StudentServiceImpl();List<Student> studentList = studentService.selectAllStudent();for (int i = 0; i < studentList.size(); i++) {System.out.println(studentList.get(i));}}// 修改学生的信息public void alterOwnInfo(int studentid){// 创建StudentService引用,指向StudentServiceImpl实现类StudentService studentService = new StudentServiceImpl();/* UPDATE student SET stname='我是学生',stsex='男',stage=15,clazzid=11,stpassword='st001'WHERE studentid = 301;*/System.out.println("请输入要修改的姓名:");String name = scan.next();System.out.println("请输入要修改的性别:");String sex = scan.next();System.out.println("请输入要修改的年龄:");int age = scan.nextInt();System.out.println("请输入要修改的班级:");int clazz = scan.nextInt();System.out.println("请输入要修改的密码:");String password = scan.next();Student student = new Student(studentid,name,sex, age, clazz, password);int result =studentService.updateStudent(student);String str = result == 1 ? "修改成功" : "修改失败";System.out.println(str);}// 删除学生的信息public void delectOwninfo(int studentid){// 创建StudentService引用,指向StudentServiceImpl实现类StudentService studentService = new StudentServiceImpl();int result = studentService.deleteStudent(studentid);String str = result == 1 ? "删除成功" : "删除失败";System.out.println(str);}//  增加学生信息public void addInfo(){// 创建StudentService引用,指向StudentServiceImpl实现类StudentService studentService = new StudentServiceImpl();System.out.println("请输入要增加学生的账号:");int studentid = scan.nextInt();System.out.println("请输入要增加学生的姓名:");String name = scan.next();System.out.println("请输入要增加学生的性别:");String sex = scan.next();System.out.println("请输入要增加学生的年龄:");int age = scan.nextInt();System.out.println("请输入要增加学生的班级:");int clazz = scan.nextInt();System.out.println("请输入要增加学生的密码:");String password = scan.next();Student student = new Student(studentid,name,sex, age, clazz, password);//增加学生信息;int result =studentService.addStudent(student);String str = result==1?"学生信息添加成功":"学生信息添加失败";System.out.println(str);}//  增加学生信息public void TeacherAddStudentInfo(int clazzid){// 创建StudentService引用,指向StudentServiceImpl实现类StudentService studentService = new StudentServiceImpl();System.out.println("请输入要增加学生的账号:");int studentid = scan.nextInt();System.out.println("请输入要增加学生的姓名:");String name = scan.next();System.out.println("请输入要增加学生的性别:");String sex = scan.next();System.out.println("请输入要增加学生的年龄:");int age = scan.nextInt();System.out.println("请输入要增加学生的密码:");String password = scan.next();Student student = new Student(studentid,name,sex, age, clazzid, password);//增加学生信息;int result =studentService.addStudent(student);String str = result==1?"学生信息添加成功":"学生信息添加失败";System.out.println(str);}}
TeacherFunctionUtils:Teacher教师的相关操作直接在这里被封装成为一个方法直接调用即可
package com.nanchu.utils;import com.nanchu.entity.Teacher;
import com.nanchu.service.TeacherService;
import com.nanchu.service.impl.TeacherServiceImpl;import java.util.List;
import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 20:14* @Version 1.0*/
public class TeacherFunctionUtils {Scanner scan = new Scanner(System.in);// 增加老师信息public void addTeacherInfo(){//创建TeacherService引用,指向TeacherServiceImpl实现类TeacherService teacherService = new TeacherServiceImpl();//增加老师信息System.out.println("请输入要增加教师的账号:");int teacherid = scan.nextInt();System.out.println("请输入要增加教师的姓名:");String name = scan.next();System.out.println("请输入要增加教师的年龄:");int age = scan.nextInt();System.out.println("请输入要增加教师的性别:");String sex = scan.next();System.out.println("请输入要增加教师所带的班级:");int clazz = scan.nextInt();System.out.println("请输入要增加教师的账号密码:");String password = scan.next();Teacher teacher = new Teacher(teacherid,name,age,sex,clazz,password);int result = teacherService.addTeacher(teacher);String str = result==1?"教师信息添加成功":"教师信息添加失败";System.out.println(str);}//删除老师public void delectTeacherInfo(int teacherid){//创建TeacherService引用,指向TeacherServiceImpl实现类TeacherService teacherService = new TeacherServiceImpl();//删除班级int result = teacherService.deleteTeacher(teacherid);String str = result == 1 ? "删除成功" : "删除失败";System.out.println(str);}// 修改老师信息public void alertTeacherInfo(int teacherid){//创建TeacherService引用,指向TeacherServiceImpl实现类TeacherService teacherService = new TeacherServiceImpl();//修改老师信息System.out.println("请输入要修改教师的姓名:");String name = scan.next();System.out.println("请输入要修改教师的年龄:");int age = scan.nextInt();System.out.println("请输入要修改教师的性别:");String sex = scan.next();System.out.println("请输入要修改教师所带的班级:");int clazz = scan.nextInt();System.out.println("请输入要修改教师的账号密码:");String password = scan.next();Teacher teacher = new Teacher(teacherid,name,age,sex,clazz,password);int result =teacherService.updateTeacher(teacher);String str = result == 1 ? "修改成功" : "修改失败";System.out.println(str);}// 查询一个老师信息public void lookOneTeacher(int teacherid ){//创建TeacherService引用,指向TeacherServiceImpl实现类TeacherService teacherService = new TeacherServiceImpl();Teacher teacher = teacherService.selectOneTeacher(teacherid);if (teacher != null) {System.out.println(teacher);} else {System.out.println("你要查询的教师信息不存在");}}// 查询一个老师信息public Teacher returnOneTeacher(int teacherid ){//创建TeacherService引用,指向TeacherServiceImpl实现类TeacherService teacherService = new TeacherServiceImpl();Teacher teacher = teacherService.selectOneTeacher(teacherid);if (teacher != null) {return teacher;} else {System.out.println("你要查询的教师信息不存在");}return null;}//查询所有教师信息public void lookAllTeacher(){//创建TeacherService引用,指向TeacherServiceImpl实现类TeacherService teacherService = new TeacherServiceImpl();List<Teacher> teacherList = teacherService.selectAllTeacher();for (int i = 0; i < teacherList.size(); i++) {System.out.println(teacherList.get(i));}}}
QueryOtherWayFunctionUtils:这里定义的是多表查询的操作,实现了dao层,没有编写service层,相关操作直接在这里被封装成为一个方法直接调用即可
package com.nanchu.utils;import com.nanchu.dao.QueryOtherWay;
import com.nanchu.dao.impl.QueryOtherWayImpl;
import com.nanchu.entity.Score;
import com.nanchu.entity.Student;
import org.junit.jupiter.api.Test;import java.util.List;/*** @Author 南初* @Create 2024/3/12 14:08* @Version 1.0*/
public class QueryOtherWayFunctionUtils {// 查看自己班级所有学生信息public void AllStudentClazz(int clazzid) {QueryOtherWay queryOtherWay = new QueryOtherWayImpl();List<Student> studentList = queryOtherWay.allStudentClazz(clazzid) ;if(studentList.size()!=0){for (int i = 0; i < studentList.size(); i++) {System.out.println(studentList.get(i));}}else{System.out.println("数据库为空,没有成绩");}}// 查看自己班级指定学生信息public void TeacherOneStudentClazz(int clazzid,int studentid) {QueryOtherWay queryOtherWay = new QueryOtherWayImpl();List<Student> studentList = queryOtherWay.OneStudentClazz(clazzid,studentid) ;if(studentList.size()!=0){for (int i = 0; i < studentList.size(); i++) {System.out.println(studentList.get(i));}}else{System.out.println("数据库为空,没有成绩");}}//自己班级所有学生所有科目成绩信息public void AllStudentAllCourseScore(int clazzid){QueryOtherWay queryOtherWay = new QueryOtherWayImpl();List<Score> scoreList = queryOtherWay.allStudentAllCourseScore(clazzid);if(scoreList.size()!=0){for (int i = 0; i < scoreList.size(); i++) {System.out.println(scoreList.get(i));}}else{System.out.println("数据库为空,没有成绩");}}//#查看自己班级所有学生指定科目成绩信息public void AllStudentOneCourseScore(int clazzid,int courseid){QueryOtherWay queryOtherWay = new QueryOtherWayImpl();List<Score> scoreList = queryOtherWay.allStudentOneCourseScore(clazzid,courseid);if(scoreList.size()!=0){for (int i = 0; i < scoreList.size(); i++) {System.out.println(scoreList.get(i));}}else{System.out.println("数据库为空,没有成绩");}}// oneStudentAllCourseScorepublic void OneStudentAllCourseScore(int clazzid,int studentid){QueryOtherWay queryOtherWay = new QueryOtherWayImpl();List<Score> scoreList = queryOtherWay.oneStudentAllCourseScore(clazzid,studentid);if(scoreList.size()!=0){for (int i = 0; i < scoreList.size(); i++) {System.out.println(scoreList.get(i));}}else{System.out.println("数据库为空,没有成绩");}}//oneStudentOneCourseScore@Testpublic void OneStudentOneCourseScore(int clazzid,int studentid,int courseid){QueryOtherWay queryOtherWay = new QueryOtherWayImpl();List<Score> scoreList = queryOtherWay.oneStudentOneCourseScore(clazzid,studentid,courseid);if(scoreList.size()!=0){for (int i = 0; i < scoreList.size(); i++) {System.out.println(scoreList.get(i));}}else{System.out.println("数据库为空,没有成绩");}}//#查看所有班级指定科目成绩信息public void AllClazzOneCourseScore(int courseid){QueryOtherWay queryOtherWay = new QueryOtherWayImpl();List<Score> scoreList = queryOtherWay.allClazzOneCourseScore(courseid);if(scoreList.size()!=0){for (int i = 0; i < scoreList.size(); i++) {System.out.println(scoreList.get(i));}}else{System.out.println("数据库为空,没有成绩");}}
}

3.4.7test测试类

AccountFunctionTest:管理员功能在这里面实现了,后面在view中的EMSystem_main主方法中直接调用AccountFunctionTest,省点事,就没有把AccountFunction管理员功能封装在view中
package com.nanchu.test;import com.nanchu.utils.*;import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 23:56* @Version 1.0*/
public class AccountFunctionTest {public static void accountLogin(){Scanner scan = new Scanner(System.in);LoginUtils loginUtils =new LoginUtils();PageUtils pageUtils= new PageUtils();ClazzFunctionUtils clazz = new ClazzFunctionUtils();CourseFunctionUtils course = new CourseFunctionUtils();TeacherFunctionUtils teacher = new TeacherFunctionUtils();StudentFunctionUtils student = new StudentFunctionUtils();ScoreFunctionUtils score = new ScoreFunctionUtils();QueryOtherWayFunctionUtils qOther = new QueryOtherWayFunctionUtils();int accountid = loginUtils.loginCheck1();while(true){pageUtils.page2();System.out.print("请输入功能选项(只能输入0~25):");int StudentFunctionId  = scan.nextInt();if(StudentFunctionId == 1){          // 查看所有班级信息clazz.lookAllClazz();}else if (StudentFunctionId == 2){   // 查看指定班级信息clazz.lookOneClazz();}else if (StudentFunctionId == 3){   // 修改指定班级信息clazz.alterClazzInfo();}else if (StudentFunctionId == 4){   // 添加班级信息clazz.addOneClazz();}else if (StudentFunctionId == 5){   // 删除指定班级信息clazz.delectClazz();}else if (StudentFunctionId == 6){   // 查看所有课程信息course.lookAllCourse();}else if (StudentFunctionId == 7){   // 查看指定课程信息course.lookOneCourse();}else if (StudentFunctionId == 8){   // 修改指定课程信息course.alertCourseInfo();}else if (StudentFunctionId == 9){   // 添加课程信息course.addCourseInfo();}else if (StudentFunctionId == 10){   // 删除指定课程信息course.delectCourseInfo();}else if (StudentFunctionId == 11){   // 查看所有老师信息teacher.lookAllTeacher();}else if (StudentFunctionId == 12){   // 查看指定老师信息System.out.print("请输入你要查看老师的编号:");int teacherid = scan.nextInt();teacher.lookOneTeacher(teacherid);}else if (StudentFunctionId == 13){   // 修改指定老师信息System.out.print("请输入你要修改老师的编号:");int teacherid = scan.nextInt();teacher.alertTeacherInfo(teacherid);}else if (StudentFunctionId == 14){   // 删除指定老师信息System.out.print("请输入你要删除老师的编号:");int teacherid = scan.nextInt();teacher.delectTeacherInfo(teacherid);}else if (StudentFunctionId == 15){   // 添加老师信息teacher.addTeacherInfo();}else if (StudentFunctionId == 16){   // 查看所有学生信息student.lookAllInfo();}else if (StudentFunctionId == 17){   // 查看指定学生信息System.out.print("请输入你要查看学生的编号:");int studentid = scan.nextInt();student.lookOwnInfo(studentid);}else if (StudentFunctionId == 18){   // 添加学生信息student.addInfo();}else if (StudentFunctionId == 19){   // 修改指定学生信息System.out.print("请输入你要修改学生的编号:");int studentid = scan.nextInt();student.alterOwnInfo(studentid);}else if (StudentFunctionId == 20){   // 删除指定学生信息System.out.print("请输入你要删除学生的编号:");int studentid = scan.nextInt();student.delectOwninfo(studentid);}else if (StudentFunctionId == 21){   // 查看所有学生成绩信息score.lookScoreAllStudent();}else if (StudentFunctionId == 22){   // 查看指定学生成绩信息System.out.print("请输入你要查看指定学生成绩信息的同学的编号:");int studentid = scan.nextInt();score.lookScoreOneStudent(studentid);}else if (StudentFunctionId == 23){   // 查看指定班级所有学生成绩信息System.out.print("请输入你要查询的班级编号:");int clazzid = scan.nextInt();qOther.AllStudentAllCourseScore(clazzid);}else if (StudentFunctionId == 24){   // 查看所有班级指定科目成绩信息System.out.print("请输入指定科目编号:");int courseid = scan.nextInt();qOther.AllClazzOneCourseScore(courseid);}else if (StudentFunctionId == 25){   // 查看指定班级指定科目成绩信息System.out.print("请输入指定班级编号:");int  clazzid = scan.nextInt();System.out.print("请输入指定科目编号:");int courseid = scan.nextInt();qOther.AllStudentOneCourseScore(clazzid,courseid);}else{break;}}}
}

 TeacherFunctionTest这里同AccountFunctionTest一样

package com.nanchu.test;import com.nanchu.entity.Student;
import com.nanchu.entity.Teacher;
import com.nanchu.utils.*;import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 23:47* @Version 1.0*/
public class TeacherFunctionTest {public static void teacherLogin() {Scanner scan = new Scanner(System.in);LoginUtils loginUtils = new LoginUtils();PageUtils pageUtils = new PageUtils();StudentFunctionUtils stu = new StudentFunctionUtils();TeacherFunctionUtils tfu = new TeacherFunctionUtils();QueryOtherWayFunctionUtils qOther = new QueryOtherWayFunctionUtils();int teacherid = loginUtils.loginCheck2();Teacher teacher = tfu.returnOneTeacher(teacherid);int clazzid = teacher.getClazzid();while (true) {pageUtils.page3();System.out.print("请输入你想要查询的功能(只能输入1~9):");int StudentFunctionId = scan.nextInt();if (StudentFunctionId == 1) {          // 查看自己的信息tfu.lookOneTeacher(teacherid);} else if (StudentFunctionId == 2) {   // 修改自己的信息tfu.alertTeacherInfo(teacherid);} else if (StudentFunctionId == 3) {   // 删除自己的信息tfu.delectTeacherInfo(teacherid);break;} else if (StudentFunctionId == 4) {   // 查看自己班级所有学生信息qOther.AllStudentClazz(clazzid);} else if (StudentFunctionId == 5) {   // 查看自己班级指定学生信息System.out.print("请输入你要查看指定学生编号:");int stuid = scan.nextInt();qOther.TeacherOneStudentClazz(clazzid,stuid);} else if (StudentFunctionId == 6) {   // 添加自己班级学生信息stu.TeacherAddStudentInfo(clazzid);} else if (StudentFunctionId == 7) {   // 修改自己班级指定学生信息System.out.print("请输入学生编号:");int stuid = scan.nextInt();Student student = stu.returnOneStudent(stuid);int stuclazz = student.getClazzid();if(clazzid == stuclazz){stu.alterOwnInfo(stuid);}else {System.out.println("你输入的学生不是您班级的学生,你无法删除此学生信息!");}} else if (StudentFunctionId == 8) {   // 删除自己班级指定学生信息System.out.print("请输入学生编号:");int stuid = scan.nextInt();Student student = stu.returnOneStudent(stuid);int stuclazz = student.getClazzid();if(clazzid == stuclazz){stu.delectOwninfo(stuid);}else {System.out.println("你输入的学生不是您班级的学生,你无法删除此学生信息!");}} else if (StudentFunctionId == 9) {   // 查看自己班级所有学生所有科目成绩信息qOther.AllStudentAllCourseScore(clazzid);}else if (StudentFunctionId == 10) {   // 查看自己班级所有学生指定科目成绩信息System.out.print("请输入指定科目编号:");int courseid = scan.nextInt();qOther.AllStudentOneCourseScore(clazzid,courseid);}else if (StudentFunctionId == 11) {   // 查看自己班级指定学生所有科目成绩信息System.out.print("请输入学生编号:");int stuid = scan.nextInt();qOther.OneStudentAllCourseScore(clazzid,stuid);}else if (StudentFunctionId == 12) {   // 查看自己班级指定学生指定科目成绩信息System.out.print("请输入你要查看指定学生编号:");int stuid = scan.nextInt();System.out.print("请输入指定科目编号:");int courseid = scan.nextInt();qOther.OneStudentOneCourseScore(clazzid,stuid,courseid);}else {break;}}}
}

 StudentFunctionTest这里同AccountFunctionTest一样

package com.nanchu.test;import com.nanchu.entity.Student;
import com.nanchu.utils.*;import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 18:51* @Version 1.0*/
public class StudentFunctionTest {public static void studentLogin() {Scanner scan = new Scanner(System.in);LoginUtils loginUtils =new LoginUtils();PageUtils pageUtils= new PageUtils();ScoreFunctionUtils sfu = new ScoreFunctionUtils();StudentFunctionUtils stu = new StudentFunctionUtils();QueryOtherWayFunctionUtils qOther = new QueryOtherWayFunctionUtils();int studentid = loginUtils.loginCheck3();while(true){pageUtils.page4();System.out.print("请输入功能选项(只能输入0~9):");int StudentFunctionId  = scan.nextInt();if(StudentFunctionId == 1){          // 查看自己的信息stu.lookOwnInfo(studentid);}else if (StudentFunctionId == 2){   // 修改自己的信息stu.alterOwnInfo(studentid);}else if (StudentFunctionId == 3){   // 删除自己的信息stu.delectOwninfo(studentid);break;}else if (StudentFunctionId == 4){   // 查看自己所有科目成绩信息sfu.lookScoreOneStudent(studentid);}else if (StudentFunctionId == 5){   // 查看自己指定科目成绩信息System.out.print("请输入你要查询的科目编号:");int courseid = scan.nextInt();sfu.lookScoreOneStudent(studentid,courseid);}else if (StudentFunctionId == 6){   // 查看自己班级所有学生所有科目成绩信息Student student = stu.returnOneStudent(studentid);int clazzid = student.getClazzid();qOther.AllStudentAllCourseScore(clazzid);}else if (StudentFunctionId == 7){   // 查看自己班级所有学生指定科目成绩信息Student student = stu.returnOneStudent(studentid);int clazzid = student.getClazzid();System.out.print("请输入你要查看的自己班级所有学生指定科目编号:");int courseid = scan.nextInt();qOther.AllStudentOneCourseScore(clazzid,courseid);}else if (StudentFunctionId == 8){   // 查看自己班级指定学生所有科目成绩信息Student student = stu.returnOneStudent(studentid);int clazzid = student.getClazzid();System.out.print("请输入你要查看自己班级指定学生编号:");int stuid = scan.nextInt();qOther.OneStudentAllCourseScore(clazzid,stuid);}else if (StudentFunctionId == 9){   // 查看自己班级指定学生指定科目成绩信息Student student = stu.returnOneStudent(studentid);int clazzid = student.getClazzid();System.out.print("请输入你要查看指定学生编号:");int stuid = scan.nextInt();System.out.print("请输入指定科目编号:");int courseid = scan.nextInt();qOther.OneStudentOneCourseScore(clazzid,stuid,courseid);}else{break;}}}
}

3.4.8view层

EMSystem_main:所有功能最后在这里展现
package com.nanchu.view;import com.nanchu.test.AccountFunctionTest;
import com.nanchu.test.StudentFunctionTest;
import com.nanchu.test.TeacherFunctionTest;
import com.nanchu.utils.PageUtils;import java.util.Scanner;/*** @Author 南初* @Create 2024/3/10 15:41* @Version 1.0*/
public class EMSystem_main {public static void main(String[] args) {Scanner scan = new Scanner(System.in);PageUtils pageUtils = new PageUtils();int identityid;while(true){pageUtils.page1();System.out.print("请选择你要登录的身份(只能输入1,2,3,0):");identityid = scan.nextInt();//  校验输入的序号,只能是0到3while (true) {if (identityid == 1 || identityid == 2 || identityid == 3 || identityid == 0) {break;} else {System.out.print("输入错误,请重新输入(只能输入1,2,3,0):");identityid = scan.nextInt();}}if(identityid == 1){   // 管理员登录AccountFunctionTest.accountLogin();}else if (identityid == 2){  // 教师登录TeacherFunctionTest.teacherLogin();}else if(identityid == 3 ){  // 学生登录StudentFunctionTest.studentLogin();}else{System.exit(0);;}}}
}

4、功能展示

        这里只展示学生登录完整功能,管理员功能和教师功能页面太多了,这里就不过多展示,需要可以自己测试实现

学生登录

1、查看自己的信息

2、 修改自己的信息

4、查看自己所有科目成绩信息

5、查看自己指定科目成绩信息

6、查看自己班级所有学生所有科目成绩信息

7、查看自己班级所有学生指定科目成绩信息

8、查看自己班级指定学生所有科目成绩信息 

9、查看自己班级指定学生指定科目成绩信息

0、退出

3、 删除自己的信息

        说明:这里删除自己的信息直接默认退出账号,从student表中直接删除全部信息,再登录这个账号就登录不了了,小心操作。

        总结:这个项目非常锻炼个人思维,从数据库表的设计,到代码功能的实现,虽然特别折磨人,但是挺锻炼个人对三层架构,jdbc操作的理解与实现,从这一个项目中体现了面向接口编程,后端全是写接口,实现接口。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/757206.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python内置对象

Python是一种强大的、动态类型的高级编程语言&#xff0c;其内置对象是构成程序的基础元素。Python的内置对象包括数字、字符串、列表、元组、字典、集合、布尔值和None等&#xff0c;每种对象都有特定的类型和用途。 01 什么是内置对象 这些对象是编程语言的基础构建块&…

STP环路避免实验(思科)

华为设备参考&#xff1a;STP环路避免实验&#xff08;华为&#xff09; 一&#xff0c;技术简介 Spanning Tree Protocol&#xff08;STP&#xff09;&#xff0c;即生成树协议&#xff0c;是一种数据链路层协议。主要作用是防止二层环路&#xff0c;并自适应网络变化和故障…

Unity2D实现鼠标拖动物体移动(简单好抄)

1.新建脚本&#xff0c;并将脚本拖到你想要拖动的物体上即可 using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine;public class text : MonoBehaviour {private Vector3 offset;public int x 1;void OnMouseDown(…

SAP前台处理:物料主数据创建<MM01>之销售视图

一、背景&#xff1a; 终于来到了物料主数据&#xff0c;我觉得物料账是SAP最重要的一项发明&#xff0c;也一直是SAP的一项重要优势&#xff0c;物料账记录了一个个物料的生生不息&#xff1b; 本章主要讲解物料主数据和财务相关的主要内容&#xff1a;这里特别提示由于作者…

matlab软件基础

第1讲 MATLAB初步 MATLAB是矩阵实验室&#xff08;Matrix Laboratory&#xff09;的简称&#xff0c;是美国MathWorks公司出品的商业数学软件&#xff0c;用于算法开发、数据可视化、数据分析以及数值计算的高级技术计算语言和交互式环境。MATLAB和Mathematica、Maple并称为三…

Linux 发布项目到OpenEuler虚拟机

后端&#xff1a;SpringBoot 前端&#xff1a;VUE3 操作系统&#xff1a;Linux 虚拟机&#xff1a;OpenEuler 发布项目是需要先关闭虚拟机上的防火墙 systemctl stop firewalld 一、运行后端项目到虚拟机 1、安装JDK软件包 查询Jdk是否已安装 dnf list installed | grep jd…

Redis数据结构对象中的类型检查与命令多态、内存回收

类型检查与命令多态 概述 redis中用于操作键的命令基本上可以分为两种类型。其中一种命令可以对任何类型的键执行&#xff0c;比如说DEL命令、EXPIRE命令、RENAME命令、TYPE命令、OBJECT命令等. 而另一种命令只能对特定类型的键执行&#xff0c;比如说 1.SET、GET、APPEND、…

OPTEE v3.20.0 FVP环境搭建

目录 一、前提条件 二、下载fvp代码 三、下载工具链 四、下载Foundation_Platform FVP平台 五、编译及运行 一、前提条件 1、安装如下的依赖工具 sudo apt-get install android-tools-adb android-tools-fastboot autoconf \ automake bc bison build-essential ccache c…

windows管理github代码

资料 windows SSH下载github

51单片机—AD/DA

目录 1.AD/DA元件介绍 2.运算放大器 3.原理分析 4.性能指标 5.内部芯片时序 6.程序实操 7.原理图 1.AD/DA元件介绍 一般传感器的值会随参数的值变化&#xff0c;AD一般对电压进行转换&#xff0c;AD有多个通道&#xff0c;但是DA只有一个通道&#xff0c;且AD的运用较为广…

路由器怎么做端口映射

路由器在网络中起到了连接不同设备和提供网络服务的重要作用。端口映射是一项常见的操作&#xff0c;它允许外部网络中的设备通过路由器访问内部网络中的设备。我们将介绍如何在路由器上进行端口映射的设置。 理解端口映射 在开始操作之前&#xff0c;我们需要了解一些基本概念…

反射 Reflection

反射 反射的概念 反射机制允许程序在执行期借助于ReflectionAPI取得任何类的内部信息(比如成员变量&#xff0c;构造器&#xff0c;成员方法等等)&#xff0c;并能操作对象的属性及方法。反射在设计模式和框架底层都会用到加载完类之后&#xff0c;在堆中就产生了一个Class类型…

Flutter 在 Windows 下的开发环境搭建(Flutter SDK 3.19.2)【图文详细教程】

Git 下载与安装 对于 Flutter 3.19&#xff0c;Git 版本需要 2.27 及以上 Git 下载&#xff1a; Git 官网&#xff1a;https://git-scm.com/Git 下载淘宝镜像&#xff1a;https://registry.npmmirror.com/binary.html?pathgit-for-windows/ 对于 Git 的安装教程&#xff0c;…

Python分析无人驾驶汽车在桂林市文旅行业推广的问卷

【项目背景】 通过市场调研、文本分析、访谈和问卷调查等方法&#xff0c;探讨&#xff1a; 网民对无人驾驶汽车出行服务的态度。无人驾驶安全员的行业背景。不同人群在旅游时的交通选择偏好。游客及当地居民对桂林市文旅路线的交通满意度。乘客对无人驾驶汽车的满意度。桂林…

超快速排序(蓝桥杯,归并排序,acwing)

题目描述&#xff1a; 在这个问题中&#xff0c;您必须分析特定的排序算法----超快速排序。 该算法通过交换两个相邻的序列元素来处理 n 个不同整数的序列&#xff0c;直到序列按升序排序。 对于输入序列 9 1 0 5 4&#xff0c;超快速排序生成输出 0 1 4 5 9。 您的任务是确…

Selenium不同版本配置自动下载驱动及打包细节

Selenium配置浏览器驱动 自动下载浏览器驱动的方法 selenium4.7.0自动下载浏览器驱动的方法 selenium4.11.0 或4.11.1手动设置浏览器驱动路径的方法pyinstaller打包程序时同时打包ChromeDriverchromedriver路径需要sys._MEIPASS的路径进行引用方法一&#xff1a;通过–add-data…

【Linux】从零开始认识进程 — 前篇

我从来不相信什么懒洋洋的自由。我向往的自由是通过勤奋和努力实现的更广阔的人生。。——山本耀司 从零开始认识进程 1 认识冯诺依曼体系2 操作系统3 进程3.1 什么是进程&#xff1f;&#xff1f;&#xff1f;3.2 进程管理PCB 3.3 Linux中的进程深入理解 3.4 进程创建总结 送给…

jvm的垃圾回收器以及触发full gc的场景

JVM&#xff08;Java虚拟机&#xff09;的垃圾回收器有很多种&#xff0c;主要包括以下几种&#xff1a; Serial收集器&#xff1a;串行收集器是最古老、最稳定的收集器。它使用单个线程进行垃圾收集工作&#xff0c;在进行垃圾回收时会暂停所有用户线程。 ParNew收集器&#…

Nebula Graph-01-Nebula Graph简介和安装以及客户端连接

前言 NoSQL 数据库 图数据库并不是可以克服关系型数据库缺点的唯一替代方案。现在市面上还有很多非关系型数据库的产品&#xff0c;这些产品都可以叫做 NoSQL。NoSQL 一词最早于上世纪 90 年代末提出&#xff0c;可以解释为“非 SQL” 或“不仅是 SQL”&#xff0c;具体解释要…

查找众数及中位数 - 华为OD统一考试(C卷)

OD统一考试&#xff08;C卷&#xff09; 分值&#xff1a; 100分 题解&#xff1a; Java / Python / C 题目描述 众数是指一组数据中出现次数量多的那个数&#xff0c;众数可以是多个。 中位数只是指把一组数据从小到大排列&#xff0c;最中间的那个数&#xff0c;如果这组数…