教务管理系统(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.rhkb.cn/news/279586.html

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

相关文章

杰发科技AC7801——读取Flash数据做CRC校验

查看Keil的编译结果发现总共6160个字节。计算结果如下&#xff0c; 代码如下 #include "ac780x_crc.h" #include "ac780x.h" #include "ac780x_debugout.h" #include "string.h" #include "ac780x_eflash.h"#define TestSi…

麒麟 V10 一键安装 Oracle 11GR2(231017)单机版

Oracle 一键安装脚本&#xff0c;演示 麒麟 V10 一键安装 Oracle 11GR2 单机版过程&#xff08;全程无需人工干预&#xff09;&#xff1a;&#xff08;脚本包括 ORALCE PSU/OJVM 等补丁自动安装&#xff09; ⭐️ 脚本下载地址&#xff1a;Shell脚本安装Oracle数据库 脚本第…

模拟面试

1.TCP通信中的三次握手和四次挥手过程 三次握手 1.客户端像向服务器端发送连接请求 2.服务器应答连接请求 3.客户端与服务器简历连接 四次挥手&#xff1a; 客户端或服务器端发起断开请求,这里假设客户端发送断开请求 1.客户端向服务器发送断开请求 2.服务器应答断开请求 3.服…

Java面试相关问题

一.MySql篇 1优化相关问题 1.1.MySql中如何定位慢查询&#xff1f; 慢查询的概念&#xff1a;在MySQL中&#xff0c;慢查询是指执行时间超过一定阈值的SQL语句。这个阈值是由long_query_time参数设定的&#xff0c;它的默认值是10秒1。也就是说&#xff0c;如果一条SQL语句的执…

【开发环境搭建篇】IDEA安装和配置

作者介绍&#xff1a;本人笔名姑苏老陈&#xff0c;从事JAVA开发工作十多年了&#xff0c;带过大学刚毕业的实习生&#xff0c;也带过技术团队。最近有个朋友的表弟&#xff0c;马上要大学毕业了&#xff0c;想从事JAVA开发工作&#xff0c;但不知道从何处入手。于是&#xff0…

单片机第四季-第一课:RTOS

1&#xff0c;RTOS来龙去脉 操作系统是什么&#xff1f; 以人类社会类比&#xff0c;小公司三四个人都是干活的&#xff0c;大公司有几万人其中有几千人从事管理工作&#xff0c;他们的工作是让其他人的干活效率更高。 51单片机为什么没有操作系统&#xff0c;因为51的性能太…

黑马微服务p30踩坑

报错详情 : orderservice开不起来 : 发生报错 : 然后检查了以下端口啥的 &#xff0c;配置啥的都是没有问题的 ; 解决办法 : 1 . 修改nacos1,2,3中的端口&#xff0c;将conf 中 cluster.conf中 的 127.0.0.1 全部改成自己本机的真实ipv4地址; 本机真实ipv4地址查看 :…

Git小乌龟安装及使用教程

一、Win7安装git 软件下载地址&#xff1a;git for windows 安装过程直接默认下一步&#xff0c;直到安装结束。 安装结束后重启一下。 安装完成后&#xff0c;在文件夹空白处右键出现以下几个标识&#xff0c;说明安装成功。 二、安装tortoise git&#xff08;乌龟git&…

(css)vue 自定义背景 can‘t resolve

(css)vue 自定义背景 can’t resolve 旧写法&#xff1a; background-image: url(/assets/images/step-bg.jpg);background-size: 100% 100%; 新写法&#xff1a; background-image: url(~/assets/images/step-bg.jpg);background-size: 100% 100%; 解决参考&#xff1a;https…

robots协议详解:爬虫也要有边界感

随着互联网的迅猛发展,信息的获取变得越来越便捷,而网络爬虫(Spider)技术就是其中之一。网络爬虫是一种自动化程序,它能够遍历互联网上的网页,提取信息,用于各种用途,例如搜索引擎索引、数据挖掘、价格比较等。但是,爬虫技术虽然强大,但是也是一把双刃剑,在正当使用…

oops-framework框架 之 启动流程(三)

引擎&#xff1a; CocosCreator 3.8.0 环境&#xff1a; Mac Gitee: oops-game-kit 回顾 上篇博客中我们通过 oops-game-kit 模版构建了基础的项目&#xff0c;另外讲解了下assets目录结构和游戏配置文件的基本使用相关&#xff0c;详情内容可参考&#xff1a; oops-framewo…

Qt 多元素控件

Qt开发 多元素控件 Qt 中提供的多元素控件有: QListWidgetQListViewQTableWidgetQTableViewQTreeWidgetQTreeView xxWidget 和 xxView 之间的区别 以 QTableWidget 和 QTableView 为例. QTableView 是基于 MVC 设计的控件. QTableView 自身不持有数据. 使用QTableView 的 …

Qt 容器类控件

Group Box 使用 QGroupBox 实现一个带有标题的分组框可以把其他的控件放到里面作为一组&#xff0c;这样看起来能更好看一点. 核心属性 属性说明title分组框的标题alignment分组框内部内容的对齐方式flat是否是 “扁平” 模式checkable是否可选择. 设为 true&#xff0c;则在…

基于nodejs+vue班级管理系统的设计与实现-flask-django-python-php

随着电子技术的普及和快速发展&#xff0c;线上管理系统被广泛的使用&#xff0c;有很多事业单位和商业机构都在实现电子信息化管理&#xff0c;班级管理系统也不例外&#xff0c;由比较传统的人工管理转向了电子化、信息化、系统化的管理。随着互联网技术的高速发展&#xff0…

Unity Toggle处理状态变化事件

Toggle处理状态变化事件&#xff0c;有两个方法。 法一、通过Inspector面板设置 实现步骤&#xff1a; 在Inspector面板中找到Toggle组件的"On Value Changed"事件。单击""按钮添加一个新的监听器。拖动一个目标对象到"None (Object)"字段&am…

【黑马头条】-day01环境搭建SpringBoot-Cloud-Nacos

文章目录 1 环境搭建及简介2 项目介绍2.1 应用2.2 业务说明2.3 技术栈2.4 收获2.5 大纲 3 Nacos准备3.1 安装Nacos 4 初始工程搭建4.1 环境准备4.1.1 导入项目4.1.2 设置本地仓库4.1.3 设置项目编码格式 4.2 全局异常4.2.1 自动装配 4.3 工程主体结构 5 登录功能开发5.1 需求分…

有什么ai写作神器?6个AI智能写作助手分享给你

随着人工智能技术的不断发展&#xff0c;自动生成文章的软件也逐渐成为了写作领域的一项重要工具。下面将介绍国内常用的6款AI写作助手&#xff0c;来看看它们的有什么不一样的地方。 爱制作AI写作 无需下载&#xff0c;直接在线使用&#xff0c;支持手机电脑操作&#xff0c;…

Android14音频进阶:AudioFlinger究竟如何混音?(六十三)

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长! 优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏:多媒体系统工程师系列【原创干货持续更新中……】🚀 人生格言: 人生从来没有捷径,只…

Mac版Jmeter安装与使用模拟分布式环境

Mac版Jmeter安装与使用&模拟分布式环境 1 安装Jmeter 1.1 安装Java环境 国内镜像地址&#xff1a;https://repo.huaweicloud.com/java/jdk/11.0.29/jdk-11.0.2_osx-x64_bin.dmg 下载dmg后&#xff0c;双击进行安装。 配置环境变量&#xff1a; # 1 打开环境变量配置文件…

软考 网工 每日学习打卡 2024/3/18

学习内容 第8章 网络安全 本章主要讲解网络安全方面的基础知识和应用技术。针对考试应该掌握诸如数据加密、报文认 证、数字签名等基本理论&#xff0c;在此基础上深入理解网络安全协议的工作原理&#xff0c;并能够针对具体的 网络系统设计和实现简单的安全解决方案。 本章共有…