【南航数据库】南航数据库实验实验报告--学生选课系统

文章目录

摘要

​ 随着近年来社会整体信息化程度的提高,各行各业都采取了各种举措提高企业的信息化程度,从而提高管理效率,降低管理成本。高校需要管理大量的学生、老师、课程等数据信息,采用手工管理的方式效率低,更易出错,提高高校信息化程度更是迫在眉睫。基于此需求提出学生选课系统的,在此系统上统一管理学生信息、教师信息、课程信息、选课信息。一方面可以方便学生老师登录系统选课,另一方面对学校来说大大节约管理信息的人力,减少信息出错可能性。

​ 技术方面,后台采用Java语言实现,前台采用Html+Css+Javascript实现,为提高开发速度,选用当前互联网公司最流行的框架SSM(Spring MVC、Spring、Mybatis)框架,前台使用BootStrap框架,数据库方面选用当前最流行的Mysql作为数据存储的数据库。

关键词: Java; SSM; BootStrap; Mysql;

ABSTRACT

​ In recent years, with the improvement of the overall information level of society, all walks of life have taken various measures to improve the information level of enterprises, so as to improve the management efficiency and reduce the management cost. Colleges and universities need to manage a large number of students, teachers, courses and other data information. Manual management is inefficient and more error prone, so it is urgent to improve the degree of informatization in Colleges and universities. Based on this demand, this paper puts forward the design of student course selection system, which manages student information, teacher information, course information and course selection information in a unified way. On the one hand, it is convenient for students and teachers to log in to the system to select courses. On the other hand, it greatly saves the manpower of information management and reduces the possibility of information error.

​ In terms of technology, the background is implemented with Java language, and the foreground is implemented with HTML + CSS + JavaScript. In order to improve the development speed, SSM (spring MVC, spring, mybatis) is the most popular framework of Internet companies, bootstrap is used in the foreground, and MySQL is the most popular database for data storage.

keywords: Java; SSM; BootStrap; Mysql;

目录

文章目录

第一章 绪论

1.1 项目开发背景

​ 在大学选课流程中,学生在选课过程时面临着可选课程多、选课的流程复杂等问题;对于老师来说查看选课信息和更改课程信息流程繁杂;对于管理者来说面临信息收集难度大,数据信息多,容易出错等问题。为了解决以上问题需要开发专门的选课系统,维护学生信息、课程信息、选课信息等。学生、教师、管理员分别具有各自不同的权限在统一平台上进行操作,简化选课流程。以上这个就是学生选课系统的项目开发背景。

1.2 主要工作和贡献

​ 本文旨在设计和开发学生选课系统,本文使用软件工程的开发流程进行开发,涵盖了可行性分析、需求分析、系统总体设计和详细设计、模块编码开发、测试等环节。

1.3 结构安排

​ 本文除了第一章绪论外,其余部分组织如下:

​ 第二章为基础实验部分,主要利用了opengauss数据库进行基础实验,掌握了数据库的一些基础操作。

​ 第三章通过相关的市场、经济、技术等调查、给出了学生选课系统的可行性分析。

​ 第四章给出了学生选课系统的需求分析,包含总体设计需求和各个功能模块需求分析。

​ 第五章是学生选课系统的总体设计,包括使用的技术简介,包括Spring boot、Mysql等技术的使用。系统功能设计、数据库设计等。

​ 第六章介绍了学生选课系统详细设计和编码实现,在这一章节中对各个模块进行详细设计的思路描述和实现说明。

​ 第七章对网站进行了页面测试和功能性测试,并根据测试结果进行相关分析。

​ 第八章介绍了总结和展望,在本章中梳理了学生选课系统的开发流程和经验教训,并对学生选课系统的不足做出分析,并展望后续的改进。

第二章 基础实验实验报告

2.1 Experiment 1&2

2.1.1 实验一: SQL 定义功能、数据插入

  1. 建立教学数据库的三个基本表:

    S(Sno,Sname,Ssex,Sage,Sdept) 学生(学号,姓名,性别,年龄,系)
    SC(Sno,Cno,Grade) 选课(学号,课程号,成绩)
    C(Cno,Cname,Cpno,Ccredit) 课程(课程号,课程名,先行课,学分)
    
  2. DROP TABLE、ALTER TABLE、CREATE INDEX、DROP INDEX 及 INSERT 语句输入数据。

2.1.2 实验二: 数据查询

  1. 查询选修 1 号课程的学生学号与姓名。
  2. 查询选修课程名为数据结构的学生学号与姓名。
  3. 查询不选 1 号课程的学生学号与姓名。
  4. 查询学习全部课程学生姓名。
  5. 查询所有学生除了选修 1 号课程外所有成绩均及格的学生的学号和平均成绩,其结果按平均成绩的降序排列。
  6. 查询选修数据库原理成绩第 2 名的学生姓名。
  7. 查询所有 3 个学分课程中有 3 门以上(含 3 门)课程获 80 分以上(含 80 分)的学生的姓名。
  8. 查询选课门数唯一的学生的学号。
  9. SELECT 语句中各种查询条件的实验。

2.1.3 实验SQL代码

# Database Experiment 1 & 2
# SQL 定义功能、数据插入 & 数据查询


create table S (
  Sno char(9) primary key,
  Sname char(20) not null,
  Ssex char(2),
  Sage smallint,
  Sdept char(20)
);

create table C (
  Cno char(4) PRIMARY KEY,
  Cname char(40) not null,
  Cpno char(4),
  Ccredit SMALLINT,
  FOREIGN KEY (Cpno) REFERENCES C(Cno)
);

CREATE TABLE SC (
  Sno CHAR(9),
  Cno CHAR(4),
  Grade SMALLINT,
  PRIMARY KEY (Sno, Cno),
  FOREIGN KEY (Sno) REFERENCES S(Sno),
  FOREIGN KEY (Cno) REFERENCES C(Cno)
);

drop PROCEDURE if EXISTS add_student_male;
DELIMITER //
  CREATE PROCEDURE add_student_male()
  BEGIN
    declare num INT;
    SET num = 0;
    while(num < 100) do
      insert into S values (concat('1600401', num), concat('student', num), '男', 20, '测试部门');
      set num = num + 1;
    end while;

  END //
DELIMITER ;

call add_student_male();


select * from S;

DROP PROCEDURE IF EXISTS add_student_female;
DELIMITER //
  CREATE PROCEDURE add_student_female()
    BEGIN
      DECLARE num INT;
      SET num = 0;
      WHILE (num<100) DO
        INSERT INTO S VALUES (concat('1600402', num), concat('student', num), '女', 20, '测试部门');
        SET num = num + 1;
      END WHILE;
    END //
DELIMITER ;

CALL add_student_female();

SELECT * from S;

insert into C(Cno, Cname, Ccredit) values ('1', '数据库', 4);
insert into C(Cno, Cname, Ccredit) values ('2', '数学', 2);
insert into C(Cno, Cname, Ccredit) values ('3', '信息系统', 4);
insert into C(Cno, Cname, Ccredit) values ('4', '操作系统', 3);
insert into C(Cno, Cname, Ccredit) values ('5', '数据结构', 4);
insert into C(Cno, Cname, Ccredit) values ('6', '数据处理', 2);
insert into C(Cno, Cname, Ccredit) values ('7', 'C语言', 4);

update C set Cpno='5' where Cno='1';
update C set Cpno='1' where Cno='3';
update C set Cpno='6' where Cno='4';
update C set Cpno='7' where Cno='5';
update C set Cpno='6' where Cno='7';

insert into S values ('201215121', '李勇', '男', 20, 'CS');
insert into S values ('201215122', '刘晨', '女', 19, 'CS');
insert into S values ('201215123', '王敏', '女', 18, 'MA');
insert into S values ('201215125', '张立', '男', 19, 'IS');

create unique index Stusno on S(Sno);
create unique index Coucno on C(Cno);
create unique index SCno on SC(Sno ASC, Cno DESC );

select * from S;

drop index Stusno on S;

select * from S;

insert into SC values ('201215121', '1', 92);
insert into SC values ('201215121', '2', 85);
insert into SC values ('201215121', '3', 88);
insert into SC values ('201215122', '2', 90);
insert into SC values ('201215122', '3', 80);

# 2-1
select S.Sno, S.Sname from S, SC where SC.Cno='1' AND S.Sno=SC.Sno;
# 2-2
select S.Sno, S.Sname from S, C, SC where C.Cname='数据结构' AND S.Sno=SC.Sno AND SC.Cno=C.Cno;
# 2-3
select S.Sno, S.Sname from S where not exists(select * from SC where Sno=S.Sno and Cno='1');
# 2-4
select Sname from S
where not exists(
  select * from C
  where not exists(
    select * from SC
    where Sno=S.Sno and Cno=C.Cno
  )
);

# 2-5
# 查询所有学生除了选修 1 号课程外所有成绩均及格的学生的学号和平均成绩,其结果按平均成绩的降序排列
select SCX.Sno, avg(SCX.Grade)
from SC SCX
where 59 < all(
  select SCY.Grade
  from SC SCY
  where SCY.Sno=SCX.Sno
    and SCY.Cno!='1'
) and SCX.Cno != '1'
group by SCX.Sno
order by avg(SCX.Grade) desc;

# 2-6
# 查询选修数据库原理成绩第 2 名的学生姓名。
select S.Sname
from SC, C, S
where C.Cname='数据库原理'
  and SC.Sno=S.Sno
  and SC.Cno=C.Cno
group by SC.Sno
order by SC.Grade desc
limit 1, 1;

# 2-7
# 查询所有 3 个学分课程中有 3 门以上(含 3 门)课程获 80 分以上(含 80 分)的学生的姓名。
select Sname
from S
where Sno in(
  select Sno
  from SC, C
  where C.Cno=SC.Cno
    and C.Ccredit=3
    and SC.Grade >= 80
  group by Sno
  having count(Grade) >= 3
);

# 2-8
# 查询选课门数唯一的学生的学号。
select Sno, count(Cno)
from SC
group by Sno;

select distinct SC.Sno
from SC, (select Sno, count(Cno) Count_CNO from SC group by Sno) as Count_SC
where not exists(
    select * from (select Sno, count(Cno) Count_CNO from SC group by Sno) as Count_SC_2
    where SC.Sno != Count_SC_2.Sno
      and Count_SC.Count_CNO=Count_SC_2.Count_CNO
  )
  and SC.Sno=Count_SC.Sno;

2.2 Experiment 3

2.2.1 实验三: 数据修改、删除

  1. 把 1 号课程的非空成绩提高 10%。
  2. 在 SC 表中删除课程名为数据结构的成绩的元组。
  3. 在 S 和 SC 表中删除学号为 95002 的所有数据。

2.2.2 实验SQL代码

# Database Experiment 3
# 数据修改、删除



# 3-1
# 把 1 号课程的非空成绩提高 10%。
update SC
set Grade = Grade * 1.1
where Grade is not null
  and Cno='1';
# How to restrict the grade below 100?
create trigger SC_Grade_below_100
after update of Grade on SC
referencing
  new row as New
for each row
begin
  if (New.Grade > 100)
    then New.Grade := 100;
  end if;
end;

# 3-2
# 在 SC 表中删除课程名为数据结构的成绩的元组。
delete
from SC
where Cno in (
    select Cno
    from C
    where Cname='数据结构'
);

# 3-3
# 在 S 和 SC 表中删除学号为 95002 的所有数据。
delete
from SC
where Sno='95002';

delete
from S
where Sno='95002';

2.3 Experiment 4

2.3.1 实验四: 视图的操作

  1. 建立男学生的视图,属性包括学号、姓名、选修课程名和成绩。
  2. 在男学生视图中查询平均成绩大于 80 分的学生学号与姓名。

2.3.2 实验SQL代码

# Database Experiment 4
# 视图的操作


# 4-1
# 建立男学生的视图,属性包括学号、姓名、选修课程名和成绩。
create view S_Boys
as
select S.Sno, S.Sname, C.Cname, SC.Grade
from S, C, SC
where S.Ssex='男'
  and S.Sno=SC.Sno
  and C.Cno=SC.Cno;


# 4-2
# 在男学生视图中查询平均成绩大于 80 分的学生学号与姓名。
select Sno, Sname
from S_Boys
group by Sno
having avg(Grade) > 80;

2.4 Experiment 5

2.4.1 实验五: 库函数,授权控制

  1. 计算每个学生有成绩的课程门数、平均成绩。
  2. 使用 GRANT 语句,把对基本表 S、SC、C 的使用权限授给其它用户。
  3. 实验完成后,撤消建立的基本表和视图。

2.4.2 实验SQL代码

# Database Experiment 5
# 库函数,授权控制


# 5-1
# 计算每个学生有成绩的课程门数、平均成绩。
select Sno, count(Cno), avg(Grade)
from SC
where Grade is not null
group by Sno;

# 5-2
# 使用 GRANT 语句,把对基本表 S、SC、C 的使用权限授给其它用户。
create user 'test_db_course_user'@'localhost' identified by 'password';

# grant all privileges
# on table S, SC, C
# to test_db_course_user;
# Due to the MySQL syntax restriction, they should be granted one by one.
grant all privileges on table S to 'test_db_course_user'@'localhost' identified by 'password';
grant all privileges on table C to 'test_db_course_user'@'localhost' identified by 'password';
grant all privileges on table SC to 'test_db_course_user'@'localhost' identified by 'password';

# 5-3
# 实验完成后,撤消建立的基本表和视图。
drop view S_Boys;

drop table SC, S, C;

drop procedure add_student_female;
drop procedure add_student_male;

drop user 'test_db_course_user'@'localhost';

第三章 可行性分析

3.1 市场可行性

​ 市场是检验项目价值大小的试金石,在传统的选课中,由各班的辅导员收集班内每个学生选课信息,再逐级上报汇总,整体效率低,成本高,并且极易出错。全国各个高校对学生选课系统具有极高的需求,所以学生选课系统的市场前景是及其广阔的。

3.2 经济可行性

​ 经济可行性是指系统投入市场后,获得的经济利益或者节约的经济利益大于开发软件所付出的成本。

​ 学生选课系统开发成本主要在人力成本以及服务器成本上。人力成本是指开发人员的设计与开发成本。服务器成本是指项目开发完成后,购买服务器部署项目的成本。

​ 本项目开发完成后,可以为学校节省大量的管理成本。此系统开发测试完成上线后,系统可以在多个高校使用,通过数量来平摊研发成本,经济上是可行的。

3.3 技术可行性

3.3.1 Java

​ Java作为一种计算机编程语言,其在企业网络和Internet环境的应用更是十分广泛,现在已成为Internet中最受欢迎、最有影响的编程语言之一。其最大的特点就是面向对象,这种面向对象的程序设计更接近我们的思维方式,相对于面向过程的程序设计,它最大的优点就是可扩展性和可维护性,这也使我们的代码更健壮。

​ 我们都知道面向对象主要有四大特性:封装、抽象、继承和多态。

​ 封装:在面向对象语言中,封装特性最为直接的体现在类中,类即现实生活中的实体的抽象,我们将其所拥有的属性和方法封装到类中,对外部我们提供相应的接口,通过实例化的对象可以调用类中封装好的属性和方法,并且在使用这些方法时并不用知晓其内部的具体实现,这是面向对象的封装特性;

​ 抽象:抽象就是将一类实体的所共同拥有的特性抽象出来,封装在一个抽象类中,抽象在面向对象语言中是由抽象类来体现的。抽象类描述的是一类事物共有的东西,而并非特指某种事物,所以在Java编程语言中体现为抽象类不能实例化;

​ 继承:继承就是指子类可以继承父类或者接口,从而可以实现代码重用,其实继承体现的是单继承关系,父类和子类本质上还是一类实体。

​ 多态:Java中的多态具有多重含义。首先多态最为直白的体现就是父类对象引用不同的子类对象实例,调用不同的子类重写的方法从而表现出不同的行为。多态能够提高代码重用,还可为程序提供更好的可扩展性。

3.3.2 J2EE

​ J2EE是一项目架构标准主要用于网页的开发通过这个标准可以制定出一些应用于企业的网站。严格地来说,J2EE并不属于一种产品而是一种约束或者是标准。有的人把它称开发的规范,因此,不管是哪一家公司他们只要在这个架构下进行开发都可以开发出一款比较实用的高级应用程序。J2EE从开发到设计,再到最后的综合管理可以构成一套完整的开发体系,J2EE是由oracle软件公司跟其他多数享誉盛名的科技公司共同努力发明并且应用起来的。J2EE是软件开发的一项标准。J2EE并非是一种生产产品,它既可以说一种开发标准,也能够说是一种开发规范。无论是哪家公司都能够在这种现有统一的标准下开发出一套属于自己企业的高级应用系统的。J2EE是一个公司级平台。它用来给那些在公司经营项目中遇到的研发、设计、系统管控有关难题进行简化。

​ J2EE可以说这一项技术是根据JAVA标准升级而成而不是凭空独创的,J2EE不断的更新和发展最终形成了现在的约束和规范。J2EE技术首先要不违背它所继承的技术和规范标准,比如说对数据库的访问以及良好的跨平台性质,以及分布式的应用。同时,还要适用于各种各样的使用人群。除此之外必须还要为其他的网页开发或者企业开发提供大量的预留接口,体现其强大的可扩展性。其他的开发人员可以通过这些预留的接口对该规范和准则进行更加标准和一致性高的开发,从而体现出J2EE标准的强大的伸缩性。那么最终的一个目的就是要使得程序开发人员在开发过程中尽量少使用市场上的一些现有的框架,从而规范一个正确的开发体系。那么,他是利用一种开发模型,此模型呈现分布式。以此来完成对所有应用的开发。在开发过程中主要根据系统的各个功能进行划分,也可将这些功能划分为不同的组件。不同的组件会存放在不同的服务器上,并通过不同的用户接口进行管理。那么使用这一标准可以明确的规范开发的流程,并且可以通过MVC来解决系统层次和架构的问题,使得开发人员更加轻松的开发代码,并且让维护人员或者后期的修改人员能更加方便地查看系统的代码和结构。

3.3.3 MySQL

​ MySQL是一款开源的数据库。它具有非常实用的价值。他属于中型数据库。MySQL提供了许多的技术支持其中包括了多操作系统的支持也包括了多线程的支持,同时也提供多种资源的支持,除此之外,还可以提供多种的数据库连接方法解决数据库并发和大量数据操作的问题 。使用MySQL的人都会认为这个数据库特别实用。由于它是完全开源和免费的,在使用成本上也不会有太大的损失,因此是目前中小型公司主要使用的数据库之一。

​ 从数据库关系来看他是一款关系型数据库具有很多优点比如说用的内存空间较小用户界面简单操作起来十分便捷并且不需要太多繁琐的安装步骤。MySQL是由MySQL公司开发而成,那么这个公司是一个什么公司呢?从历史数据来看它是一个非常有商业眼光的公司,也是非常成功的一个公司,它所开发的产品都受到了人们的青睐。MySQL本身的特性也非常的突出,他能够兼容多种操作系统,同时也能兼容多种的编程语言,比如说Linux环境下使用,也同时能够支持多种编程语言并为这些编程语言提供他们所要使用的用户接口。在性能方面具有处理大数据高并发的处理能力,并且不会占用太多的主机内存,这一点相对其他的数据库要好很多。MySQL的架构:

image-20220625000425532
图2-1 Mysql架构服务图

第四章 需求分析

4.1 系统总体设计需求分析

image-20220625000630411
图3-1 系统总体需求结构图
  • 用户模块:不同用户角色(学生、老师、管理员)用户登陆及退出和用户信息的维护等。

  • 课程模块:包含课程的信息维护及选课操作等。

  • 教师模块:包含教师信息维护、所教课程的信息维护。

  • 学生模块:包含学生信息维护、所选课程维护等信息。

4.2 系统功能模块需求分析

4.2.1 用户模块需求分析

(1)用户需要分三个角色:学生、教师、系统管理员,不同的角色具有不同的操作权限。

  • ① 学生角色:具有查看课程、选课和退选、管理自己个人信息(如修改密码)。
  • ② 教师角色:具有添加和管理课程、查看自己课程的选课结果、管理个人信息(修改密码等)
  • ③ 管理员角色:就有学生管理、课程管理、教师管理、添加学生、添加教师、添加课程等。

(2)登录功能:不同的用户输入用户名和密码后,选择自己所属角色,点击登录按钮,登录。进入系统主页面后,点击注销则退出登录。

4.2.2 课程模块需求分析

(1)课程模块具有课程管理的功能:

  • ① 添加课程:新增一门课程,输入课程编号、课程名称、课程所属学院、所属专业、课程类型。
  • ② 删除课程:选中某个课程后,点击可删除课程。
  • ③ 修改课程信息:选中某个课程后,点击修改,可以查看和修改课程的信息。

(2)选课模块

  • ①学生登录系统后,可以查看课程,选中想要的课程后,点击确定选课,则选择完成课程。
  • ② 学生登录系统后;可以查看自己已选的课程并且可以退选课程、查看已修的课程。
  • ③ 教师登录系统后,可以查看自己负责教授的课程的选课情况。

4.2.3教师模块需求分析

教师模块负责教师信息和所教授的课程维护。

  • ① 教师登录后可以查看个人的信息,修改个人信息。
  • ② 教师登录后,可以查看自己所教授课程的选课情况。

4.2.4学生模块需求分析

学生模块负责学生信息和所教授的课程维护。

  • ① 学生登录后可以查看个人的信息,修改个人信息。
  • ② 学生登录后,可以查看自己所选课程的选课信息。

第五章 系统的总体设计

5.1 开发技术与工具

​ 本节介绍学生选课系统使用的技术与工具

开发技术:

  • 前端HTML+CSS+JAVASCRIPT

  • 后端SSM(SpringMVC + Spring+Mybatis)框架

  • 前端BootStrap 框架

  • 数据库Mysql

    开发工具:

  • Intellij IDEA 后端开发工具

  • Vscode 前端开发工具

  • Navicat 数据库可视化工具

5.2 系统架构图

5.2.1 系统的逻辑架构

image-20220625001825326
图4-1 系统逻辑结构图

5.3 数据库设计

image-20220625002023506
图4-2 数据库E-R图

5.3.1 学生信息表:student

字段类型字段说明
Sidvarchar(12)主键,唯一标识,学号
Snamevarchar(20)学生姓名
Sidcardvarchar(20)学生卡号
Ssexvarchar(18)性别
Spasswordvarchar(50)密码
Sagevarchar(2)年龄
Classrvarchar(50)班级
Professionvarchar(50)专业
collegevarchar(50)学院

创建表信息如下:

CREATE TABLE `student`  (
  `Sid` char(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
  `Sname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Sidcard` char(18) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Ssex` varchar(18) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Spassword` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Sage` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Classr` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `profession` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `college` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`Sid`) USING BTREE,
  INDEX `class`(`Classr`) USING BTREE
);

5.3.2 教师信息表:teacher

字段类型字段说明
Tidvarchar(4)主键,唯一标识
Tnamevarchar(20)用户名
Tpasswordvarchar(12)密码
Tsexvarchar(10)性别
Introductionvarchar(100)介绍

​ 创建表信息如下:

CREATE TABLE `teacher`  (
  `Tid` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
  `Tname` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Tpassword` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Tsex` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Introduction` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`Tid`) USING BTREE
); 

5.3.3 管理员信息表:admin

字段类型字段说明
ANameVarchar(12)主键,唯一标识
APasswordvarchar(12)密码

​ 创建表信息如下:

CREATE TABLE `admin`  (
  `Aname` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Apassword` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`Aname`) USING BTREE
);

5.3.4 课程信息表:course

字段类型字段说明
Cidvarchar(4)主键,唯一标识
Cnamevarchar(100)课程id
Cintroductionvarchar(100)课程介绍
Typevarchar(100)课程类型
belongcollvarchar(100)所属专业
belongprovarchar(100)所属学院

​ 创建表信息如下:

CREATE TABLE `course`  (
  `Cid` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
  `Cname` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `Cintroduction` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Type` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `belongcoll` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `belongpro` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`Cid`) USING BTREE
);

5.3.5 课程计划表:courseplan

字段类型字段说明
Courseclassvarchar(12)主键,课程名称
coursetimevarchar(12)课程时间
courseweekvarchar(12)课程上课的周
cidchar(4)课程id
tidchar(4)授课教师id
classroomvarchar(6)上课地点
creditsint(11)创建时间
periodint(11)课程时期
Totalnumint(11)总课时

​ 创建表信息如下:

CREATE TABLE `courseplan`  (
  `Courseclass` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `coursetime` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `courseweek` varchar(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `cid` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `tid` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `classroom` varchar(6) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `credits` int(11) NULL DEFAULT NULL,
  `period` int(11) NULL DEFAULT NULL,
  `Totalnum` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`Courseclass`) USING BTREE,
  INDEX `cid`(`cid`) USING BTREE,
  INDEX `tid`(`tid`) USING BTREE,
  CONSTRAINT `courseplan_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `course` (`Cid`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `courseplan_ibfk_2` FOREIGN KEY (`tid`) REFERENCES `teacher` (`Tid`) ON DELETE CASCADE ON UPDATE CASCADE
);

5.3.6 课程成绩表:grade

字段类型字段说明
idvarchar(11)主键,唯一标识
sidvarchar(11)学生id
cidvarchar(11)课程id
gradeint(3)分数
creditsvarchar(255)等级

​ 创建表信息如下:

CREATE TABLE `grade`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `sid` char(12) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `cid` char(4) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL,
  `grade` int(3) NULL DEFAULT NULL,
  `credits` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
);

5.3.7 学生选课映射表:sc

字段类型字段说明
idvarchar(11)主键,唯一标识
cidvarchar(4)课程id
sidVarchar(12)课程id

​ 创建表信息如下:

CREATE TABLE `sc`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cid` char(4) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `sid` char(12) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `cid`(`cid`) USING BTREE,
  INDEX `sid`(`sid`) USING BTREE,
  CONSTRAINT `sc_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `course` (`Cid`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `sc_ibfk_2` FOREIGN KEY (`sid`) REFERENCES `student` (`Sid`) ON DELETE CASCADE ON UPDATE CASCADE
);

第六章 系统详细设计与实现

6.1 登录模块的实现

6.1.1 登录模块功能

​ 登录模块功能:

  • 学生登录和退出功能
  • 教师登录与退出功能
  • 管理员登录与退出功能

6.1.2 用户接口设计

接口名称URL接口说明
管理员登录接口/LoginHandler/adminlogin管理登录
管理员注销登录接口/LoginHandler/adminlogout管理员退出登录
学生登录接口/LoginHandler/studentlogin学生登录
学生注销登录接口/LoginHandler/studentlogout学生退出登录
教师登录接口/LoginHandler/teacherlogin老师登录
教师注销登录接口/LoginHandler/teacherlogout老师退出登录

6.1.3 类设计

​ LoginHandler:登录登出接口控制,负责对接用户登录和登出相关的HTTP请求接口,并将请求转发给对应的服务类。

​ AdminService:管理员功能实现类,实现了管理员的相关的接口功能。如登录、登出

​ TeacherService:教师功能实现类,实现了教师相关的功能接口实现功能,如在用户模块中实现了教师角色的登录和登出功能。

​ StudentService:学生类功能实现类,实现了学生相关的功能接口实现,如学生角色永辉登录和登出功能。

核心代码:LoginHandler

package net.fuzui.StudentInfo.handler;

import net.fuzui.StudentInfo.pojo.Student;
import net.fuzui.StudentInfo.pojo.Teacher;
import net.fuzui.StudentInfo.service.AdminService;
import net.fuzui.StudentInfo.service.CoursePlanService;
import net.fuzui.StudentInfo.service.CourseService;
import net.fuzui.StudentInfo.service.SelectCourseService;
import net.fuzui.StudentInfo.service.StudentService;
import net.fuzui.StudentInfo.service.TeacherService;
import net.fuzui.StudentInfo.service.impl.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;



@Controller
@RequestMapping("/LoginHandler")
public class LoginHandler {
    @Autowired
    AdminService adminServiceImpl;
    @Autowired
	StudentService studentService;
    @Autowired
	TeacherService teacherService;
    
  //管理员登录

    @RequestMapping("/adminlogin")
    public String loginStudent(@RequestParam("aname") String aname, @RequestParam("apassword") String apassword,
                               Model model, HttpSession httpSession) {
        String n = null;
        n = adminServiceImpl.queryByNamePwd(aname,apassword);

        if (n != null && !"".equals(n)) {
            httpSession.setAttribute("aname", aname);
            return "admin/adminFace";
        } else {
            return "login";
        }

    }

    // 管理员退出登录
    @RequestMapping("/adminlogout")
    public ModelAndView adminLogout(HttpSession httpSession) {
        httpSession.removeAttribute("aname");
        httpSession.removeAttribute("couList");
        return new ModelAndView(new RedirectView("/StudentInfo/index.jsp"));
    }
    
    
 // 学生登录
 	@RequestMapping("/studentlogin")
 	public ModelAndView loginStudent(@RequestParam("sid") String sid, @RequestParam("spassword") String spassword,
 			Model model, HttpSession httpSession, HttpServletRequest httpRequest) {

 		Student student = new Student();
 		student = studentService.getByStuSid(sid);
 		if (studentService.queryByNamePwd(sid, spassword) != null) {
 			httpSession.setAttribute("sid", sid);
 			httpSession.setAttribute("sname", student.getSname());
 			return new ModelAndView(new RedirectView("../student/studentFace.jsp"));
 		} else {
 			httpRequest.setAttribute("msg","账号或密码不正确,登录失败!");
 			return new ModelAndView(new RedirectView("../fail.jsp"));
 		}

 	}
 	
 // 学生退出登录
 	@RequestMapping("/studentlogout")
 	public ModelAndView studentLogout(HttpSession httpSession) {

 		httpSession.removeAttribute("sid");
 		httpSession.removeAttribute("sname");
 		httpSession.removeAttribute("courseList");
 		httpSession.removeAttribute("ssrList");
 		httpSession.removeAttribute("sesList");
 		return new ModelAndView(new RedirectView("/StudentInfo/index.jsp"));
 	}
    
 	
 	
 // 教师登录
 	@RequestMapping("/teacherlogin")
 	public ModelAndView loginTeacher(@RequestParam("tid") String tid, @RequestParam("tpassword") String tpassword,
 			Model model, HttpSession httpSession) {

 		if (teacherService.queryByNamePwd(tid, tpassword) != null) {

 			Teacher teacher = new Teacher();
 			teacher = teacherService.getByTeaTid(tid);
 			// model.addAttribute("tid", tid);
 			httpSession.setAttribute("tid", tid);
 			httpSession.setAttribute("tname", teacher.getTname());
 			// httpSession.setAttribute("teachername", teacher.getTname());
 			return new ModelAndView(new RedirectView("../teacher/teacherFace.jsp"));

 		} else {
 			return new ModelAndView(new RedirectView("../fail.jsp"));
 		}

 	}

 // 教师退出登录
 	@RequestMapping("/teacherlogout")
 	public ModelAndView teacherLogout(HttpSession httpSession) {

 		httpSession.removeAttribute("tid");
 		httpSession.removeAttribute("tname");
 		httpSession.removeAttribute("couList");
 		httpSession.removeAttribute("sesList");
 		httpSession.removeAttribute("lookList");

 		return new ModelAndView(new RedirectView("/StudentInfo/index.jsp"));
 	}
}

6.2 管理员模块的实现

6.2.1 管理员模块功能

​ 管理员模块功能:管理员登录后,进入主页面,主页面顶部六个功能按钮:

  • 学生管理
  • 教师管理
  • 添加学生
  • 添加教师
  • 修改老师信息
  • 修改学生信息

6.2.2 管理员接口设计

接口名称URL接口说明
新增学生接口/AdminHandler/addStudent新增学生
删除学生接口/AdminHandler/delete/{sid}删除学生
修改学生接口/AdminHandler/moditystu/{sid}修改学生信息
新增老师接口/AdminHandler/addTeacher新增老师
删除老师接口/AdminHandler/deleteTea/{tid}删除老师
修改老师接口/AdminHandler/modityTea/{tid}修改老师接口

6.2.3 类设计

​ AdminHandler:管理员接口控制类,负责处理前台发起的查询管理员相关的HTTP请求,并将请求转入服务层处理类进行处理。

​ TeacherService:教师功能实现类,实现了教师相关的功能接口实现功能,这里实现了老师的新增老师,删除老师,修改老师信息等功能。

​ StudentService:学生类功能实现类,实现了学生相关的功能接口实现,如新增学生、修改学生信息,删除学生等功能。

核心代码:AdminHandler

package net.fuzui.StudentInfo.handler;

import net.fuzui.StudentInfo.pojo.Student;
import net.fuzui.StudentInfo.pojo.Teacher;
import net.fuzui.StudentInfo.service.AdminService;
import net.fuzui.StudentInfo.service.CoursePlanService;
import net.fuzui.StudentInfo.service.CourseService;
import net.fuzui.StudentInfo.service.SelectCourseService;
import net.fuzui.StudentInfo.service.StudentService;
import net.fuzui.StudentInfo.service.TeacherService;
import net.fuzui.StudentInfo.service.impl.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;



@Controller
@RequestMapping("/AdminHandler")
//@SessionAttributes("studentList")
//@SessionAttributes("teacherList")
public class AdminHandler {


    @Autowired
	StudentService studentService;
	@Autowired
	TeacherService teacherService;
	@Autowired
	CoursePlanService coursePlanService;
	@Autowired
    CourseService courseService;
	@Autowired
	SelectCourseService selectCourseService;



	String[] arr_belongcoll = {"计算机学院","理学院","外国语学院","航空学院"};
	String[][] arr_belongpro = {
                    {"计算机科学与技术","信息安全","软件工程","物联网工程"},
                    {"数学","物理","计算数学", "应用物理"},
                    {"英语", "日语", "俄语", "西班牙语"},
                    {"飞行器设计", "飞行器制造", "飞行器动力", "飞行器维修"}
				};

	String[][][] arr_belongcla = {
                {
						{"1619101","1619102","1619103","1619104"},
						{"1619201","1619202","1619203","1619204"},
						{"1619301","1619302","1619303","1619304"},
						{"1619401","1619402","1619403","1619404"}

                },
                {
						{"0819101","0819102","0819103","0819104"},
						{"0819201","0819202","0819203","0819204"},
						{"0819301","0819302","0819303","0819304"},
						{"0819401","0819402","0819403","0819404"}

                },
                {
						{"1419101","1419102","1419103","1419104"},
						{"1419201","1419202","1419203","1419204"},
						{"1419301","1419302","1419303","1419304"},
						{"1419401","1419402","1419403","1419404"}

				},
                {
						{"0119101","0119102","0119103","0119104"},
						{"0119201","0119202","0119203","0119204"},
						{"0119301","0119302","0119303","0119304"},
						{"0119401","0119402","0119403","0119404"}

				}
		};

 // 添加
 	@RequestMapping("/addStudent")
 	public String addStudent(Student student, Model model) {
 		
 		
 		
 		
 		int col = Integer.parseInt(student.getCollege());
 		int pro = Integer.parseInt(student.getProfession());
 		int cla = Integer.parseInt(student.getClassr());
 		//总感觉前端js写的有问题。
 		student.setCollege(arr_belongcoll[pro]);
 		student.setProfession(arr_belongpro[pro][col]);
 		student.setClassr(arr_belongcla[pro][col][cla]);
 		
 		
 		
 		if (studentService.insertStudent(student) != 0) {
 			model.addAttribute("student", student);
 			return "success";
 			// return "admin/addStudent";
 		} else {
 			return "fail";
 		}

 	}
 	//查询全部学生方法
 	public void queryStu(HttpServletRequest request) {
 		List<Student> studentList = new ArrayList<Student>();
 		studentList = studentService.selectStudentBySql(1,10);
 		
 		
 		request.setAttribute("slist", studentList);
 	}

 	public void pageIn(Model model,List list) {
 		PageInfo page = new PageInfo(list, 5);
	 	model.addAttribute("pageInfo", page);
 	}
 	
 	// 查询
 	@RequestMapping(value = "/query/{pn}", method = RequestMethod.GET)
 	public String redirect(@RequestParam("serc") String serc, @RequestParam("condition") String condition,HttpServletRequest request,
 			@PathVariable(value = "pn") String pn,Model model) {

 		int no = Integer.parseInt(pn);
// 		System.out.println("-----"+no+"----");
 		List<Student> studentList = new ArrayList<Student>();
 		PageHelper.startPage(no, 5);
 		request.setAttribute("serc", serc);
		request.setAttribute("condition", condition);
 		//查询全部
 		if (serc.equals("all")) {
 			
 			
 			
 	 		
 			System.out.println("------------------------------------------------------------------------------------------------");
// 			studentList = studentService.selectStudentBySql(1,10);
// 			//model.addAttribute("studentList", studentList);
// 			request.setAttribute("slist", studentList);
// 			System.out.println("00000"+request.getAttribute("slist"));
// 			System.out.println(studentList);
 			studentList = studentService.selectStudentBySql(1,10);
 			pageIn(model, studentList);
 	 		request.setAttribute("slist", studentList);
 			return "admin/queryStudent";

 		//根据学号查询
 		} else if (serc.equals("sid")) {

 			studentList = studentService.getByStudentSid(1,10,condition);
 			pageIn(model, studentList);
 			request.setAttribute("slist", studentList);
 			System.out.println("sid");

 			return "admin/queryStudent";

 		//根据学院查询
 		} else if (serc.equals("col")) {
 			
 			
 			studentList = studentService.getByStudentCol(1,10,condition);
 			pageIn(model, studentList);
 			request.setAttribute("slist", studentList);
 			System.out.println(studentList);
 			System.out.println("col");
 			return "admin/queryStudent";

 		//根据专业查询
 		} else if (serc.equals("pro")) {
 			studentList = studentService.getByStudentPro(1,10,condition);
 			pageIn(model, studentList);
 			request.setAttribute("slist", studentList);
 			System.out.println(studentList);
 			System.out.println("pro");
 			return "admin/queryStudent";

 		//根据班级查询
 		} else if (serc.equals("cla")) {
 			studentList = studentService.getByStudentCla(1,10,condition);
 			pageIn(model, studentList);
 			//model.addAttribute("studentList", studentList);
 			request.setAttribute("slist", studentList);
// 			System.out.println(studentList);
// 			System.out.println("cla");
 			return "admin/queryStudent";

 		} else {

// 			studentList = studentService.selectStudentBySql(1,10);
// 			model.addAttribute("studentList", studentList);
// 			request.setAttribute("slist", studentList);
// 			System.out.println("00000"+request.getAttribute("slist"));
// 			System.out.println(studentList);
 			studentList = studentService.selectStudentBySql(1,10);
 			pageIn(model, studentList);
 	 		request.setAttribute("slist", studentList);
 			return "admin/queryStudent";

 		}

 	}

 	// 删除学生
 	@RequestMapping(value = "/delete/{sid}", method = RequestMethod.GET)
 	public String deleteStudent(@PathVariable(value = "sid") String sid, Model model) {


 		if (studentService.deleteStudent(sid) != 0) {
 			System.out.println("success");
 			
 			return "success";
 		} else {
 			System.out.println("fail");
 			return "fail";
 		}

 	}

 	// 跳转页面
 	@RequestMapping(value = "/finalPage", method = RequestMethod.GET)
 	public String finalPage(HttpServletRequest request) {
 		queryStu(request);
 		return "admin/queryStudent";
 	}

 	// 修改定位
 	@RequestMapping(value = "/moditystu/{sid}", method = RequestMethod.GET)
 	public String editPre(@PathVariable("sid") String sid, HttpServletRequest request) {

 		List<Student> studentList = new ArrayList<Student>();
 		studentList = studentService.getByStudentSid(1,10,sid);
 		
 		request.setAttribute("studentList", studentList);
 		System.out.println("-----进入修改");
 		return "admin/modiStudent";
 	}

 	
 	
 	// 修改
 	@RequestMapping(value = "/moditystud/{sid}", method = RequestMethod.GET)
 	public String update(@PathVariable("sid") String sid, Student student, HttpServletRequest request) {

 		int col = Integer.parseInt(student.getCollege());
 		int pro = Integer.parseInt(student.getProfession());
 		int cla = Integer.parseInt(student.getClassr());
 		//总感觉前端js写的有问题。
 		student.setCollege(arr_belongcoll[pro]);
 		student.setProfession(arr_belongpro[pro][col]);
 		student.setClassr(arr_belongcla[pro][col][cla]);
 		
 		if (studentService.modifyStudent(student) != 0) {
 			System.out.println("----修改成功--------------------------------------------------------------------------------------------------------");
 			return "success";
 		} else {
 			System.out.println("----修改失败----------------------------------------------------------------");
 			return "fail";
 		}
 	}
 	
 	
 	

 	// 跳转页面
 	@RequestMapping("/managestu/{pn}")
 	public String manageStudent(HttpServletRequest request,
 			@PathVariable(value = "pn") String pn,Model model) {
 		int no = Integer.parseInt(pn);
 		
 		PageHelper.startPage(no, 5);
 		List<Student> studentList = new ArrayList<Student>();
 		studentList = studentService.selectStudentBySql(1,100);
 		pageIn(model, studentList);
 		request.setAttribute("slist", studentList);
 		return "admin/queryStudent";
 	}
 		
 	// 跳转页面
 	@RequestMapping("/managetea/{pn}")
 	public String manageTeacher(HttpServletRequest request,
 			@PathVariable(value = "pn") String pn,Model model) {
 		int no = Integer.parseInt(pn);
 		PageHelper.startPage(no, 5);
 		List<Teacher> teacherList = new ArrayList<Teacher>();
	 	teacherList = teacherService.selectTeacherBySql(1,10);
	 	pageIn(model, teacherList);
	 	request.setAttribute("teacherList", teacherList);
 		return "admin/queryTeacher";
 	}


 	// 跳转页面
 	@RequestMapping("/addstu")
 	public String adStudent() {
 		return "admin/addStudent";
 	}

 	// 跳转页面
 	@RequestMapping("/addtea")
 	public String adTeacher() {
 		return "admin/addTeacher";
 	}

 	// 跳转页面
 	@RequestMapping("/addcou")
 	public String adCourse() {
 		return "admin/addCourse";
 	}
 	
 // 添加
 	@RequestMapping("/addTeacher")
 	public String addTeacher(Teacher teacher, Model model, HttpSession httpSession) {

 		if (teacherService.insertTeacher(teacher) != 0) {
 			model.addAttribute("teacher", teacher);

 			//---------------------------------待优化-----同样不能实时刷新--------------------------------------------
 			return "success";
 			//return new ModelAndView(new RedirectView("/StudentInfo/TeacherHandler/finalPage"));
 			// return "techer/teacherFace";
 		} else {
 			return "fail";
 			//return new ModelAndView(new RedirectView("fail"));
 		}

 	}

 	
 	/**
 	 * 教师相关
 	 */
 	
 	//查询全部教师方法
 	 	public void queryTea(HttpServletRequest request) {
 	 		List<Teacher> teacherList = new ArrayList<Teacher>();
 	 		teacherList = teacherService.selectTeacherBySql(1,10);
 	 		request.setAttribute("teacherList", teacherList);
 	 	}
 	
 	// 查询
 	@RequestMapping(value = "/queryTea/{pn}", method = RequestMethod.GET)
 	public String redirectTea(@RequestParam("serc") String serc, @RequestParam("condition") String condition,HttpServletRequest request,
 			@PathVariable(value = "pn") String pn,Model model) {
 		int no = Integer.parseInt(pn);
 		PageHelper.startPage(no, 5);
 		List<Teacher> teacherList = new ArrayList<Teacher>();
 		request.setAttribute("serc", serc);
		request.setAttribute("condition", condition);
 		
 		if (serc.equals("all")) {

 			teacherList = teacherService.selectTeacherBySql(1,10);
 			pageIn(model, teacherList);
 	 		request.setAttribute("teacherList", teacherList);
 			return "admin/queryTeacher";

 		} else if (serc.equals("tid")) {

 			teacherList = teacherService.getByTeacherTid(1,10,condition);
 			pageIn(model, teacherList);
 			request.setAttribute("teacherList", teacherList);
 			System.out.println("tid");

 			return "admin/queryTeacher";

 		} else {

 			teacherList = teacherService.selectTeacherBySql(1,10);
 			pageIn(model, teacherList);
 	 		request.setAttribute("teacherList", teacherList);
 			return "admin/queryTeacher";

 		}

 	}
 	
 	

 	//删除教师
 	@RequestMapping(value = "/deleteTea/{tid}", method = RequestMethod.GET)
 	public String deleteTeacher(@PathVariable(value = "tid") String tid, Model model) {


 		if (teacherService.deleteTeacher(tid) != 0) {
 			System.out.println("success");
 //------------------------代优化,现状:删除后需要手动刷新界面或者重新查询,不能实时刷新。---------------------------------------------------
 			return "success";
 		} else {
 			System.out.println("fail");
 			return "fail";
 			
 		}

 	}

 	@RequestMapping(value = "/finalPageTea", method = RequestMethod.GET)
 	public String finalPageTea(HttpServletRequest request) {
 		queryTea(request);
 		return "admin/queryTeacher";
 	}

 	//修改定位,可优化
 	@RequestMapping(value = "/modityTea/{tid}", method = RequestMethod.GET)
 	public String editPreTea(@PathVariable("tid") String tid, HttpServletRequest request) {

 		List<Teacher> teacherList = new ArrayList<Teacher>();
 		teacherList = teacherService.getByTeacherTid(1,10,tid);
 		//model.addAttribute("teacherList", teacherList);
 		request.setAttribute("teacherList", teacherList);

 		return "admin/modiTeacher";
 	}

 	// 修改
 	@RequestMapping(value = "/modityTeac/{tid}", method = RequestMethod.GET)
 	public String update(@PathVariable("tid") String tid, Teacher teacher, HttpServletRequest request) {

 		if (teacherService.modifyTeacher(teacher) != 0) {
 			return "success";
 		} else {
 			return "fail";
 		}
 	}
    
    
}

6.3 课程模块的实现

6.3.1 课程功能

​ 课程模块功能:

  • 维护课程信息
  • 新增课程
  • 查询课程信息
  • 学生选课
  • 删除已选课程
  • 查看已选课程

6.3.2 课程模块接口设计

接口名称URL接口说明
增加课程接口/CourseHandler/addCourse增加课程信息
查询课程接口信息/CourseHandler/query/{pn}查询课程详细信息
删除课程/CourseHandler/delete/{cid}删除课程信息
修改课程信息/CourseHandler//moditystu/{cid}修改课程信息接口
新增课程/CoursePlanHandler/doaddcouplan/{tid}新增课程
查询课程方案/CoursePlanHandler/querycouplan/{cid}查询课程方案
查询所有课程方案/CoursePlanHandler/queryy/{pn}查询所有课程方案
修改课程方案/CoursePlanHandler/modicouplan/{courseclass}修改课程方案
删除选课方案/CoursePlanHandler//delcouplan/{courseclass}/{tid}删除选课方案

6.3.3 类设计

​ CourseHandler:课程相关控制类,负责接收前端发起的课程类的HTTP请求,并将请求转发到对应的核心服务类中,进行业务处理。

​ CourseService:课程模块核心业务类,对课程进行相关的增删改查操作,在此类中具体实现。

​ CoursePlanHandlr:选课相关的控制类,主要提供选课相关接口的控制,并调用选课相关具体服务类进行选课业务。

​ CoursePlanService:选课相关服务类,对选课相关的核心业务进行具体的处理和实现。

核心代码:CourseHandler

package net.fuzui.StudentInfo.handler;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import net.fuzui.StudentInfo.pojo.Course;
import net.fuzui.StudentInfo.pojo.Teacher;
import net.fuzui.StudentInfo.service.CourseService;

///StudentInfo/CourseHandler/query
@Controller
@RequestMapping("/CourseHandler")
@SessionAttributes("courseList")
public class CourseHandler {
	@Autowired
    CourseService courseService;

	// 添加课程
	@RequestMapping("/addCourse")
	public String addCourse(Course course, Model model) {
		

		if (courseService.insertCourse(course) != 0) {
			model.addAttribute("course", course);
			return "success";
		} else {
			return "fail";
		}
	}

	public void pageIn(Model model,List list) {
 		PageInfo page = new PageInfo(list, 5);
	 	model.addAttribute("pageInfo", page);
 	}
	
	public void queryCou(HttpServletRequest request) {
		List<Course> courseList = new ArrayList<Course>();
	 	courseList = courseService.selectCourseBySql(1,10);
	 	request.setAttribute("courseList", courseList);
	}

	@RequestMapping(value = "/query/{pn}", method = RequestMethod.GET)
	public String redirect(@RequestParam("serc") String serc, @RequestParam("condition") String condition,
						   HttpServletRequest request,@PathVariable(value = "pn") String pn,Model model) {

		int no = Integer.parseInt(pn);
		List<Course> courseList = new ArrayList<Course>();
		PageHelper.startPage(no, 5);
		request.setAttribute("serc", serc);
		request.setAttribute("condition", condition);


		if (serc.equals("all")) {


			courseList = courseService.selectCourseBySql(1,10);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			return "admin/queryCourse";

		} else if (serc.equals("sid")) {

			courseList = courseService.getByCourseCid(1,10,condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println("sid");

			return "admin/queryCourse";

		} else if (serc.equals("nam")) {
			courseList = courseService.getByCourseCname(1,10,condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			System.out.println("cla");
			return "admin/queryCourse";

		} else if (serc.equals("col")) {
			courseList = courseService.getByCourseCol(1,10,condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			System.out.println("col");
			return "admin/queryCourse";

		} else if (serc.equals("type")) {
			courseList = courseService.getByCourseType(1,10,condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			System.out.println("pro");
			return "admin/queryCourse";

		} else {

			courseList = courseService.selectCourseBySql(1,10);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			return "admin/queryCourse";

		}

	}




	//删除学生
	@RequestMapping(value = "/delete/{cid}", method = RequestMethod.GET)
	public String deleteStudent(@PathVariable(value = "cid") String cid, HttpServletRequest request) {


		if (courseService.deleteCourse(cid) != 0) {
			System.out.println("success");
			queryCou(request);
			return "success";
		} else {
			System.out.println("fail");
			return "fail";
		}

	}

	//跳转到queryCourse页面
	@RequestMapping(value = "/finalPage", method = RequestMethod.GET)
	public String finalPage(HttpSession httpSession,HttpServletRequest request) {
		Object admin = request.getSession().getAttribute("courseList");
 		System.out.println(admin+"111111111111111111111111111111111111111111111111111111111111111111111111111");
		return "admin/queryCourse";
	}

	/**
	 * 	修改课程定位
	 * @param cid
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/moditystu/{cid}", method = RequestMethod.GET)
	public String editPre(@PathVariable("cid") String cid, HttpServletRequest request) {

		
		List<Course> courseList = new ArrayList<Course>();
		courseList = courseService.getByCourseCid(1,10,cid);
		request.setAttribute("courseList", courseList);

		return "admin/modiCourse";
	}

	//修改课程信息
	@RequestMapping(value = "/moditystud/{cid}", method = RequestMethod.GET)
	public String update(@PathVariable("cid") String cid, Course course, Model model) {
		
		if (courseService.modifyCourse(course) != 0) {
			return "success";
		} else {
			return "fail";
		}
	}

	
	//跳转到queryCourse页面
	@RequestMapping("/managecou/{pn}")
	public String manageCourse(HttpServletRequest request,@PathVariable(value = "pn") String pn,Model model) {
		int no = Integer.parseInt(pn);
		List<Course> courseList = new ArrayList<Course>();
		PageHelper.startPage(no, 5);
		courseList = courseService.selectCourseBySql(1,10);
	 	pageIn(model, courseList);
	 	request.setAttribute("courseList", courseList);
		return "admin/queryCourse";
	}
}


6.4 学生模块的实现

6.4.1 学生模块功能

​ 学生模块功能:

  • 选课功能
  • 查看已选课程
  • 退选课程
  • 查看已修课程

6.4.2 学生接口设计

接口名称URL接口说明
查询学生个人信息/StudentHandler/queryvitastu/{sid}查询学生个人信息
修改密码/StudentHandler/moditypasswordstu/{sid}修改密码
根据课程查看课程教师/StudentHandler/selcou/{cid}根据课程查看课程教师
学生选课/StudentHandler/seling学生选课
查看选课结果/StudentHandler/selcouresult/{sid}/{pn}查看选课结果
退选课程/StudentHandler/exitsel/{cid}/{sid}退选课程

6.4.3 类设计

​ StudentHandler:学生控制类,接收浏览器的HTTP请求,匹配请求的URL,并将请求转发到对应的服务类中.

​ StudentService:学生选课相关功能核心业务类,实现了学生选课的功能,如选课、退选。查询课程信息等。

核心代码:StudentHandler

package net.fuzui.StudentInfo.handler;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import net.fuzui.StudentInfo.pojo.Course;
import net.fuzui.StudentInfo.pojo.CoursePlan;
import net.fuzui.StudentInfo.pojo.Grade;
import net.fuzui.StudentInfo.pojo.StuExitSelect;
import net.fuzui.StudentInfo.pojo.StuSelectResult;
import net.fuzui.StudentInfo.pojo.Student;
import net.fuzui.StudentInfo.pojo.Teacher;
import net.fuzui.StudentInfo.service.CoursePlanService;
import net.fuzui.StudentInfo.service.CourseService;
import net.fuzui.StudentInfo.service.GradeService;
import net.fuzui.StudentInfo.service.SelectCourseService;
import net.fuzui.StudentInfo.service.StudentService;
import net.fuzui.StudentInfo.service.TeacherService;


@Controller
@RequestMapping("/StudentHandler")
public class StudentHandler {

	@Autowired
	StudentService studentService;
	@Autowired
	TeacherService teacherService;
	@Autowired
	CoursePlanService coursePlanService;
	@Autowired
	CourseService courseService;
	@Autowired
	SelectCourseService selectCourseService;
	@Autowired
	GradeService gradeService;

	// 查询
	@RequestMapping("/queryvitastu/{sid}")
	public String queryVita(@PathVariable(value = "sid") String sid, Model model) {

		Grade grade = new Grade();
		String credits = gradeService.queryCreditsSum(sid);
		Student student = new Student();
		student = studentService.getByStuSid(sid);
		model.addAttribute("sid", student.getSid());
		model.addAttribute("sname", student.getSname());
		model.addAttribute("sidcard", student.getSidcard());
		model.addAttribute("ssex", student.getSsex());
		model.addAttribute("spassword", student.getSpassword());
		model.addAttribute("sage", student.getSage());
		model.addAttribute("classr", student.getClassr());
		model.addAttribute("profession", student.getProfession());
		model.addAttribute("college", student.getCollege());
		model.addAttribute("credits", credits);

		System.out.println(student);
		System.out.println(student.getSpassword());

		return "student/queryVitaStu";
	}

	// 跳转页面
	@RequestMapping("/moditypwstu/{sid}")
	public ModelAndView teacherModi(@PathVariable(value = "sid") String sid, Model model) {

		return new ModelAndView(new RedirectView("/StudentInfo/student/modityPwStu.jsp"));
	}

	// 修改
	@RequestMapping("/moditypasswordstu/{sid}")
	public ModelAndView teacherModiPw(@PathVariable(value = "sid") String tid,
			@RequestParam("spassword") String spassword, Model model) {
		if (studentService.modifyStudentPwd(spassword, tid) != 0) {
			return new ModelAndView(new RedirectView("../queryvitastu/{sid}"));
		} else {
			return new ModelAndView(new RedirectView("../fail.jsp"));
		}

	}

	public void pageIn(Model model, List list) {
		PageInfo page = new PageInfo(list, 5);
		model.addAttribute("pageInfo", page);
	}

	// 查询
	@RequestMapping(value = "/queryy/{pn}", method = RequestMethod.GET)
	public String redirect(@RequestParam("serc") String serc, @RequestParam("condition") String condition,
			HttpServletRequest request, @PathVariable(value = "pn") String pn, Model model) {
		int no = Integer.parseInt(pn);
		List<Course> courseList = new ArrayList<Course>();
		PageHelper.startPage(no, 5);
		request.setAttribute("serc", serc);
		request.setAttribute("condition", condition);

		if (serc.equals("all")) {

			courseList = courseService.selectCourseBySql(1, 10);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			return "student/selCourse";

		} else if (serc.equals("sid")) {

			courseList = courseService.getByCourseCid(1, 10, condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println("sid");

			return "student/selCourse";

		} else if (serc.equals("nam")) {
			courseList = courseService.getByCourseCname(1, 10, condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			System.out.println("cla");
			return "student/selCourse";

		} else if (serc.equals("col")) {
			courseList = courseService.getByCourseCol(1, 10, condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			System.out.println("col");
			return "student/selCourse";

		} else if (serc.equals("type")) {
			courseList = courseService.getByCourseType(1, 10, condition);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			System.out.println("pro");
			return "student/selCourse";

		} else {

			courseList = courseService.selectCourseBySql(1, 10);
			pageIn(model, courseList);
			request.setAttribute("courseList", courseList);
			System.out.println(courseList);
			return "student/selCourse";

		}

	}

	// 查询,根据cid查询老师
	@RequestMapping(value = "/selcou/{cid}", method = RequestMethod.GET)
	public String selCou(@PathVariable(value = "cid") String cid, Model model) {

		// 代优化
		List<CoursePlan> lists = null;
		lists = coursePlanService.getTidByCoursePlanCid(1, 10, cid);
		System.out.println("------" + lists.size());
		Teacher teacher = new Teacher();
		Course course = new Course();
		if (lists.size() != 0) {
			System.out.println("-----进入选课");
			String tid = lists.get(0).getTid();
			teacher = teacherService.getByTeaTid(tid);
			model.addAttribute("tname", teacher.getTname());
			model.addAttribute("inroduction", teacher.getIntroduction());
			System.out.println(teacher.getIntroduction() + "-----------------------");
			course = courseService.getByCouCid(cid);
			model.addAttribute("cname", course.getCname());
			model.addAttribute("cid", cid);
			return "student/seling";

		} else {
			System.out.println("-----进入无教师选课");
			course = courseService.getByCouCid(cid);
			model.addAttribute("cname", course.getCname());
			model.addAttribute("cid", cid);
			return "student/noseling";
		}

	}

	// 加入课程
	@RequestMapping("/seling")
	public String confirmSelect(@RequestParam("cid") String cid, @RequestParam("sid") String sid, Model model,
			HttpSession httpSession, HttpServletRequest httpRequest) {
		// 判断是否加入过此课程
		if (selectCourseService.existCourse(cid, sid) != null) {
			httpRequest.setAttribute("msg", "已经加入过该课程,不能重复加入!");
			System.out.println("已经加入过该课程,不能重复加入!");
			return "fail";
		}
		if (selectCourseService.selectCourse(cid, sid) != 0) {
			System.out.println(cid);
			System.out.println(sid);
			return "success";
		} else {
			return "fail";
		}

	}

	// 退出
	@RequestMapping("/backseling/{cid}")
	public ModelAndView backConfirmSelect(@PathVariable(value = "cid") String cid) {

		return new ModelAndView(new RedirectView("/StudentInfo/StudentHandler/selqueryy/1"));

	}

	// 跳转页面
	@RequestMapping("/selqueryy/{pn}")
	public String selQueryy(HttpServletRequest request, @PathVariable(value = "pn") String pn, Model model) {
		int no = Integer.parseInt(pn);
		List<Course> courseList = new ArrayList<Course>();
		PageHelper.startPage(no, 5);
		courseList = courseService.selectCourseBySql(1, 10);
		pageIn(model, courseList);
		request.setAttribute("courseList", courseList);
		return "student/selCourse";
	}

	// 学生查询本人选课
	@RequestMapping(value = "/selcouresult/{sid}/{pn}", method = RequestMethod.GET)
	public String selcouresult(@PathVariable("sid") String sid, StuSelectResult ssr, HttpServletRequest request,
			@PathVariable(value = "pn") String pn, Model model) {

		List<StuSelectResult> ssrList = new ArrayList<StuSelectResult>();
		ssrList = selectCourseService.getSCBySid(1, 10, sid);
		pageIn(model, ssrList);
		request.setAttribute("ssrList", ssrList);

		return "student/selectedCourse";

	}

	// 所选课程列表详情-----退选
	@RequestMapping(value = "/exitchoose/{sid}/{pn}", method = RequestMethod.GET)
	public String exitChoose(@PathVariable("sid") String sid, StuSelectResult ssr, HttpServletRequest request,
			@PathVariable(value = "pn") String pn, Model model) {

		List<StuExitSelect> sesList = new ArrayList<StuExitSelect>();
		sesList = selectCourseService.getExitBysid(1, 10, sid);
		pageIn(model, sesList);
		request.setAttribute("sesList", sesList);

		return "student/exitSel";

	}

	// 退选
	@RequestMapping(value = "/exitsel/{cid}/{sid}", method = RequestMethod.GET)
	public ModelAndView exitSel(@PathVariable("cid") String cid, @PathVariable("sid") String sid) {

		if (selectCourseService.deleteSC(cid, sid) != 0) {
			return new ModelAndView(new RedirectView("/StudentInfo/StudentHandler/exitchoose/{sid}/1"));
		} else {
			return new ModelAndView(new RedirectView("../fail.jsp"));
		}

	}

	// 学生查询本人选课
	@RequestMapping(value = "/endcourse/{sid}/{pn}", method = RequestMethod.GET)
	public String endcourse(@PathVariable("sid") String sid, Grade grade, HttpServletRequest request,
			@PathVariable(value = "pn") String pn, Model model) {

		List<Grade> endCourseList = new ArrayList<Grade>();
		endCourseList = gradeService.getEedCourseBySid(1, 10, sid);
		pageIn(model, endCourseList);
		request.setAttribute("endCourseList", endCourseList);

		return "student/endCourse";

	}

}

6.5 教师模块的实现

6.4.1 教师模块的功能

​ 教师模块功能:

  • 选课功能
  • 查看已选课程
  • 退选课程
  • 查看已修课程

6.4.2 教师接口设计

接口名称URL接口说明
查询教师个人信息/TeacherHandler/queryvita/{tid}查询教师个人信息
管理教师课程/TeacherHandler/managecou/{tid}/{pn}管理教师所属课程
修改教师密码/TeacherHandler/moditypassword/{tid}修改教师密码
查看所选课程情况/TeacherHandler/looksel/{cid}/{cname}/{pn}查看所选课程情况
查看课程成绩/TeacherHandler//endcougrade/{cid}/{cname}/{pn}查看课程成绩
添加成绩/TeacherHandler/addGrade添加成绩

6.4.3 类设计

​ TeacherHandler:教师控制类,接收浏览器的HTTP请求,匹配请求的教师接口URL,并将请求转发到对应的服务类中.

​ TeacherService:教师课程、成绩相关功能核心业务类,实现了教师维护个人选课的功能,如查看和修改教师个人成绩、维护选课信息、录入和查看学生成绩等。

​ 核心代码:TeacherHandler

package net.fuzui.StudentInfo.handler;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import net.fuzui.StudentInfo.pojo.Course;
import net.fuzui.StudentInfo.pojo.CourseGrade;
import net.fuzui.StudentInfo.pojo.CoursePlan;
import net.fuzui.StudentInfo.pojo.Grade;
import net.fuzui.StudentInfo.pojo.StuExitSelect;
import net.fuzui.StudentInfo.pojo.StuSelectResult;
import net.fuzui.StudentInfo.pojo.Student;
import net.fuzui.StudentInfo.pojo.Teacher;
import net.fuzui.StudentInfo.service.CoursePlanService;
import net.fuzui.StudentInfo.service.CourseService;
import net.fuzui.StudentInfo.service.GradeService;
import net.fuzui.StudentInfo.service.SelectCourseService;
import net.fuzui.StudentInfo.service.StudentService;
import net.fuzui.StudentInfo.service.TeacherService;


@Controller
@RequestMapping("/TeacherHandler")

public class TeacherHandler {

	@Autowired
	StudentService studentService;
	@Autowired
	TeacherService teacherService;
	@Autowired
	CoursePlanService coursePlanService;
	@Autowired
	CourseService courseService;
	@Autowired
	SelectCourseService selectCourseService;
	@Autowired
	GradeService gradeService;

	// 添加
	@RequestMapping("/addcou")
	public String addCou() {
		return "teacher/addCou";
	}

	@RequestMapping("/sercsc")
	public String sercSC() {
		return "teacher/serchSC";
	}

	/*
	* 
	*/
	@RequestMapping("/queryvita/{tid}")
	public String queryVita(@PathVariable(value = "tid") String tid, Model model) {
		Teacher teacher = new Teacher();
		teacher = teacherService.getByTeaTid(tid);
		model.addAttribute("tid", teacher.getTid());
		model.addAttribute("tname", teacher.getTname());
		model.addAttribute("tpassword", teacher.getTpassword());
		model.addAttribute("tsex", teacher.getTsex());
		model.addAttribute("introduction", teacher.getIntroduction());
		System.out.println(teacher);
		System.out.println(teacher.getTpassword());

		return "teacher/queryVita";
	}

	public void pageIn(Model model, List list) {
		PageInfo page = new PageInfo(list, 5);
		model.addAttribute("pageInfo", page);
	}

	@RequestMapping("/managecou/{tid}/{pn}")
	public String manageCou(@PathVariable(value = "tid") String tid, Model model, HttpSession httpSession,
			@PathVariable(value = "pn") String pn) {
		// Course course = new Course();
		// CoursePlan coursePlan = new CoursePlan();
		int no = Integer.parseInt(pn);
		PageHelper.startPage(no, 5);

		List<CoursePlan> coursePlanList = new ArrayList<CoursePlan>();
		List<Course> couList = new ArrayList<Course>();

		coursePlanList = coursePlanService.getByCoursePlanTid(1, 10, tid);
		pageIn(model, coursePlanList);
		// 通过tid查出cid
		// ------------------此处有bug
		List<CoursePlan> lists = coursePlanService.getCidByCoursePlanTid(1, 3, tid);

		if (lists.size() != 0) {
			for(int i = 0 ; i<lists.size() ; i++)
			{
				CoursePlan coursePlan = lists.get(i);
				List<Course> tempCouList = courseService.getByCourseCid(1, 10, coursePlan.getCid());
				if(tempCouList.size()>=1){
					couList.add(tempCouList.get(0));
				}
			}
			httpSession.setAttribute("coursePlanList", coursePlanList);
			httpSession.setAttribute("couList", couList);
		}

		// 通过cid查出课程
//		if (lists.size() != 0) {
//			couList = courseService.getByCourseCid(1, 10, lists.get(0).getCid());
//
//			httpSession.setAttribute("coursePlanList", coursePlanList);
//			httpSession.setAttribute("couList", couList);
//
//			System.out.println(coursePlanList);
//
//			System.out.println(couList);
//		}
		return "teacher/manageCourse";
	}

	// 修改
	@RequestMapping("/moditypw/{tid}")
	public ModelAndView teacherModi(@PathVariable(value = "tid") String tid, Model model, HttpServletRequest request) {
		System.out.print(request.getRemoteAddr());
		return new ModelAndView(new RedirectView("../../teacher/modityPw.jsp"));
	}

	@RequestMapping("/moditypassword/{tid}")
	public ModelAndView teacherModiPw(@PathVariable(value = "tid") String tid,
			@RequestParam("tpassword") String tpassword, Model model) {
		if (teacherService.modifyTeacherPwd(tpassword, tid) != 0) {
			return new ModelAndView(new RedirectView("../queryvita/{tid}"));
		} else {
			return new ModelAndView(new RedirectView("../fail.jsp"));
		}

	}

	@RequestMapping(value = "/sercsc/{tid}/{pn}", method = RequestMethod.GET)
	public String sercChoose(@PathVariable("tid") String tid, StuSelectResult ssr, Model model, HttpSession httpSession,
			@PathVariable(value = "pn") String pn) {

		int no = Integer.parseInt(pn);
		PageHelper.startPage(no, 5);

		List<StuExitSelect> sesList = new ArrayList<StuExitSelect>();
		sesList = selectCourseService.getLookByTid(1, 10, tid);
		pageIn(model, sesList);
		httpSession.setAttribute("sesList", sesList);

		return "teacher/serchSC";

	}

	// 查询
	@RequestMapping(value = "/looksel/{cid}/{cname}/{pn}", method = RequestMethod.GET)
	public String lookChoose(@PathVariable("cid") String cid, @PathVariable("cname") String cname, Model model,
			HttpSession httpSession, @PathVariable(value = "pn") String pn, HttpServletRequest request) {

		int no = Integer.parseInt(pn);
		PageHelper.startPage(no, 5);
		List<Student> lookList = new ArrayList<Student>();
		lookList = selectCourseService.getByStuSid(1, 10, cid);
		pageIn(model, lookList);
		httpSession.setAttribute("lookList", lookList);
		model.addAttribute("cname", cname);
		request.setAttribute("cid", cid);
		request.setAttribute("cname", cname);

		return "teacher/printStudent";

	}

	// 结课查询页
	@RequestMapping(value = "/endcou/{cid}/{cname}/{pn}", method = RequestMethod.GET)
	public String endCourse(@PathVariable("cid") String cid, @PathVariable("cname") String cname, Model model,
			HttpSession httpSession, @PathVariable(value = "pn") String pn, HttpServletRequest request) {

		int no = Integer.parseInt(pn);
		PageHelper.startPage(no, 5);
		List<Student> lookList = new ArrayList<Student>();
		lookList = selectCourseService.getByStuSid(1, 10, cid);
		pageIn(model, lookList);
		httpSession.setAttribute("lookList", lookList);
		model.addAttribute("cname", cname);
		request.setAttribute("cid", cid);
		request.setAttribute("cname", cname);

		return "teacher/endCourse";

	}
	
	
	// 结课成绩查询页
		@RequestMapping(value = "/endcougrade/{cid}/{cname}/{pn}", method = RequestMethod.GET)
		public String endCourseGrade(@PathVariable("cid") String cid, @PathVariable("cname") String cname, Model model,
				HttpSession httpSession, @PathVariable(value = "pn") String pn, HttpServletRequest request) {

			int no = Integer.parseInt(pn);
			PageHelper.startPage(no, 5);
			List<CourseGrade> lookList = new ArrayList<CourseGrade>();
			lookList = coursePlanService.getCourseGrade(1, 10, cid);
			pageIn(model, lookList);
			httpSession.setAttribute("lookList1", lookList);
			
			request.setAttribute("cname", cname);

			return "teacher/endCourseGrade";

		}

	// 添加成绩
	@RequestMapping(value = "/addGrade", method = RequestMethod.POST)
	public String addGrade(@RequestParam("cid") String cid, @RequestParam("sid") String sid,
			@RequestParam("grade") Integer grade, Model model, HttpServletRequest request) {


		Grade g = new Grade();
		g.setCid(cid);
		g.setSid(sid);
		g.setGrade(grade);
		
		/**
		 * 根据cid查学分
		 */
		if(grade >= 60) {
			Integer credits = coursePlanService.getCreditsByCid(cid);
			g.setCredits(credits);
		}
		
		gradeService.insertGrade(g);
		
		System.out.println(g.toString());
		return "teacher/endCourse";

	}

}

第七章 系统测试

7.1 测试方法

​ 测试主要分两个方面:页面测试和功能测试。页面测试是确认页面样式是否存在漏洞,如页面样式不整齐,不同浏览器下页面显示不一致。功能测试主要是测试网站的功能是否正常,点击按钮是否得到准确的响应或者录入的信息和显示的信息是否正确。

7.2 管理员测试

​ 使用管理员账号 admin/admin登录系统,分别测试管理员的六大功能:

  • 管理员登录
  • 学生管理
  • 课程管理
  • 教师管理
  • 添加学生
  • 添加教师
  • 添加课程

​ 测试截图如下:

管理员登录

image-20220625005039512
图6-1 管理员登录界面 **学生管理**
image-20220625005151371
图6-2 学生管理界面

教师管理

image-20220625005234899
图6-3 教师管理界面

课程管理

image-20220625005312439
图6-4 课程管理界面

添加学生

image-20220625005410101
图6-5 添加学生界面

添加教师

image-20220625005447356
图6-6 添加教师界面

添加课程

image-20220625005527238
图6-7 添加课程界面

7.3 学生测试

​ 使用学生账号:201507021227/00000 账号登录系统,测试以下几个功能:

  • 学生登录
  • 选课功能
  • 查看看选课结果
  • 退选
  • 查看已修课程
  • 管理个人信息

学生登录

image-20220625005757026
图6-8 学生登录界面

选课功能

image-20220625005838298
图6-9 选课功能界面 **查看选课结果**
image-20220625005943323
图6-10 查看选课结果界面 **退选**
image-20220625010021673
图6-11 退选功能界面 **查看已修课程(分数已经出来了)**
image-20220625010330783
图6-12 查看已修课程界面

管理个人信息

image-20220625010444065
图6-13 管理个人信息界面

7.4 教师测试

​ 使用教师账号:0002/111111 登录系统,测试教师相关的功能:

  • 教师登录
  • 添加教学课程
  • 管理教学课程
  • 查看名单结果
  • 管理本人信息

教师登录

image-20220625010604554
图6-14 教师登录界面

添加教学课程

image-20220625010647755
图6-15 添加教学课程界面
image-20220628021220637
图6-16 添加失败
image-20220628021257056
图6-17 可以添加时显示的添加信息

管理教学课程

image-20220625010736655
图6-18 管理教学课程界面

查看名单结果

image-20220625010824279
图6-19 查看名单结果界面

打分并查看成绩

image-20220625010930304
图6-20 打分并查看成绩界面

管理本人信息

image-20220625011002246
图6-21 管理个人信息界面

修改课程

image-20220628021444469
图6-22 修改教学课程信息界面

第八章 总结与展望

8.1 总结

8.2 展望

目前的学生选课系统也有很多不足之,主要体现在:

  • 数据库表结构的优化与索引,由于请求并发量不高,此类问题没有暴露出来,对数据库表的设计具有较大的优化空间。
  • 未能使用Redis、消息队列等中间件,在许多业务场景中,可以使用中间件可以优化业务体验。如热数据可以存储在Redis中,并与Mysql数据库中数据一致。
  • 缺少移动端项目,使用移动端可以使用手机进行选课操作,方便了师生选课的操作。
  • 未进行性能测试,在高并发量无法确定系统可以承受的TPS,有可能导致系统崩溃

后期我会进一步完善该系统,使功能更加完善。

参考文献

[1] 王珊,萨师煊. 数据库系统概论. 第五版[M]. 北京: 高等教育出版社,2014

[2] 霍金明,孙滨,周贤来 javaWeb程序设计 电子科技大学出版 2019

[3] 张红娟, 傅婷婷编著. 《数据库原理》[M], 西安电子科技大学出版社, 2016

[4] 西尔伯沙茨著.《数据库系统概念》[M], 机械工业出版社, 2000

[5] 详解第一范式、第二范式、第三范式、BCNF范式.

[6] https://blog.csdn.net/wenco1/article/details/88077279

[7] ER图设计的原则、方法与步骤.https://www.cnblogs.com/vvlj/p/12750674.html

  • 13
    点赞
  • 80
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NUAA_Peter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值