作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
在线考试系统分为前后台,分为学生、老师、管理员三种角色;前台学生登录,后台老师、管理员登录;
前台学生登录主要功能包括:
登录、注册、考试中心参加教师分配的考试内容、查看考试历史,回顾考试试卷;
管理员主要功能包括:
首页试卷统计;
基本信息:年级管理、科目管理;
班级管理:班级管理、各班人数折线图统计;
教师管理:教师信息增删改查;
学生管理:学生信息增删改查、学生考试平均成绩柱状图统计;
试卷管理:包括查看试题、添加试题、生成试题;
试题管理:试题列表,导入试题;
考试安排管理:待考信息;
以往考试信息:考试记录;
教师登录后功能菜单与管理员相同,但会限制当前教师的权限;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
技术栈
1. 后端:Spring SpringMVC MyBatis
2. 前端:JSP+bootstrap+jQuery+Echarts
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
学生用户名:xiepengfei 密码:123
管理员用户名:ylrc 密码:123456
教师用户名:liyinping 密码:123456
运行截图
相关代码
管理员首页
package com.taohan.online.exam.handler;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.google.gson.Gson;
import com.taohan.online.exam.service.ExamPaperInfoService;
import com.taohan.online.exam.service.StudentInfoService;
import com.taohan.online.exam.service.SubjectInfoService;
import com.taohan.online.exam.service.TeacherInfoService;
/**
*
* <p>Title: AdminHomeHandler</p>
* <p>Description: 后台首页相关</p>
* @author: taohan
* @date: 2018-9-18
* @time: 下午1:59:22
* @version: 1.0
*/
@Controller
public class AdminHomeHandler {
@Autowired
ExamPaperInfoService examPaperInfoService;
@Autowired
SubjectInfoService subjectInfoService;
@Autowired
TeacherInfoService teacherInfoService;
@Autowired
StudentInfoService studentInfoService;
@Autowired
Gson gson;
private Logger logger = Logger.getLogger(AdminHomeHandler.class);
@RequestMapping("/homeInfo")
public void homeInfo(HttpServletResponse response) throws IOException {
logger.info("加载后台首页相关数据");
int examPaperTotal = examPaperInfoService.getExamPpaerTotal();
int subjectTotal = subjectInfoService.getSubjectTotal();
int teacherTotal = teacherInfoService.getTeacherTotal();
int studentTotal = studentInfoService.getStudentTotal();
String json = "{\"examPaperTotal\":"+examPaperTotal+", " +
"\"subjectTotal\":"+subjectTotal+", " +
"\"teacherTotal\":"+teacherTotal+", " +
"\"studentTotal\":"+studentTotal+"}";
response.getWriter().print(json);
}
}
科目信息
package com.taohan.online.exam.handler;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.taohan.online.exam.po.CourseInfo;
import com.taohan.online.exam.po.GradeInfo;
import com.taohan.online.exam.service.CourseInfoService;
import com.taohan.online.exam.service.GradeInfoService;
/**
*
* <p>Title: CourseInfoHandler</p>
* <p>Description: 科目</p>
* @author: taohan
* @date: 2018-8-15
* @time: 下午5:32:03
* @version: 1.0
*/
@Controller
@SuppressWarnings("all")
public class CourseInfoHandler {
@Autowired
private CourseInfoService courseInfoService;
@Autowired
private GradeInfoService gradeInfoService;
private Logger logger = Logger.getLogger(CourseInfoHandler.class);
/**
* 获取科目信息
* @param gradeId 年级编号
* @param division 分科情况
* @return
*/
@RequestMapping("/courses")
public ModelAndView getCourses(@RequestParam(value="gradeId", required=false) Integer gradeId,
@RequestParam(value="division", required=false) Integer division) {
logger.info("获取科目集合 年级条件 "+gradeId+" 分科条件 "+division);
ModelAndView model = new ModelAndView();
model.setViewName("/admin/courses");
CourseInfo course = new CourseInfo();
if (gradeId != null)
course.getGrade().setGradeId(gradeId);
if (division != null)
course.setDivision(division);
List<CourseInfo> courses = courseInfoService.getCourses(course);
model.addObject("courses", courses);
return model;
}
/**
* 根据科目编号获取学科信息
* @param courseId 科目编号
* @return
*/
@RequestMapping("/course/{courseId}")
public ModelAndView getCourseById(@PathVariable("courseId") Integer courseId) {
logger.info("获取科目信息 科目编号 "+courseId);
ModelAndView model = new ModelAndView();
model.setViewName("/admin/courseedit");
CourseInfo course = courseInfoService.getCourseById(courseId);
model.addObject("course", course);
/** 获取所有年级列表 */
List<GradeInfo> grades = gradeInfoService.getGrades();
model.addObject("grades", grades);
return model;
}
/**
* 添加/修改科目信息
* @param courseId 科目编号
* @param isUpdate 标识是否为修改操作
* @param courseName 科目名称
* @param division 分科情况
* @param gradeId 年级编号
* @return
*/
@RequestMapping(value="/course/course", method=RequestMethod.POST)
public String isUpdateOrAddCourse(@RequestParam(value="courseId", required=false) Integer courseId,
@RequestParam(value="isupdate", required=false) Integer isUpdate,
@RequestParam("courseName") String courseName,
@RequestParam("division") Integer division,
@RequestParam("gradeId") Integer gradeId) {
CourseInfo course = new CourseInfo();
course.setCourseId(courseId);
course.setCourseName(courseName);
course.setDivision(division);
GradeInfo grade = new GradeInfo();
grade.setGradeId(gradeId);
course.setGrade(grade);
//修改
if (isUpdate != null) {
logger.info("修改科目 "+course+" 的信息");
int row = courseInfoService.isUpdateCourse(course);
}
//添加
else {
logger.info("添加科目 "+course+" 的信息");
int row = courseInfoService.isAddCourse(course);
}
return "redirect:/courses";
}
/**
* 删除科目
* @param courseId 待删除科目编号
* @return
*/
@RequestMapping(value="/course/{courseId}", method=RequestMethod.DELETE)
public String isDelTeacher(@PathVariable("courseId") Integer courseId) {
logger.info("删除科目 "+courseId);
int row = courseInfoService.isDelCourse(courseId);
return "redirect:/courses";
}
/**
* 预添加科目信息
* @return
*/
@RequestMapping("/preAddCourse")
public ModelAndView preAddCourse() {
logger.info("预添加科目信息");
ModelAndView model = new ModelAndView();
model.setViewName("/admin/courseedit");
/** 获取年级集合 */
List<GradeInfo> grades = gradeInfoService.getGrades();
model.addObject("grades", grades);
return model;
}
}
班级信息
package com.taohan.online.exam.handler;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.google.gson.Gson;
import com.taohan.online.exam.charts.StudentCount;
import com.taohan.online.exam.po.ClassInfo;
import com.taohan.online.exam.po.GradeInfo;
import com.taohan.online.exam.po.TeacherInfo;
import com.taohan.online.exam.service.ClassInfoService;
import com.taohan.online.exam.service.GradeInfoService;
import com.taohan.online.exam.service.TeacherInfoService;
/**
*
* <p>Title: ClassInfoHandler</p>
* <p>Description: 班级</p>
* @author: taohan
* @date: 2018-8-13
* @time: 下午2:18:14
* @version: 1.0
*/
@Controller
@SuppressWarnings("all")
public class ClassInfoHandler {
@Autowired
private ClassInfoService classInfoService;
@Autowired
private GradeInfoService gradeInfoService;
@Autowired
private TeacherInfoService teacherInfoService;
@Autowired
private TeacherInfo teacher;
@Autowired
private ClassInfo classInfo;
@Autowired
private Gson gson;
private Logger logger = Logger.getLogger(ClassInfoHandler.class);
/**
* 获取所有班级
* @param gradeId 年级编号
* @param className 班级名称 可用于模糊查询
* @param classId 班级编号
* @return
*/
@RequestMapping(value="/classes", method=RequestMethod.GET)
public ModelAndView getClasses(@RequestParam(value="gradeId", required=false) Integer gradeId,
@RequestParam(value="className", required=false) String className,
@RequestParam(value="classId", required=false) Integer classId) {
logger.info("获取班级集合 条件:gradeId: "+gradeId+", 班级编号:"+classId+", 班级:"+className);
ModelAndView model = new ModelAndView();
ClassInfo classInfo = new ClassInfo();
/*处理查询条件*/
if (gradeId != null) {
GradeInfo gradeInfo = new GradeInfo();
gradeInfo.setGradeId(gradeId);
classInfo.setGrade(gradeInfo);
}
if (classId != null)
classInfo.setClassId(classId);
if (className != null) {
if (className.trim() != "")
classInfo.setClassName(className);
}
List<ClassInfo> classes = classInfoService.getClasses(classInfo);
model.setViewName("admin/classes");
model.addObject("classes", classes);
return model;
}
/**
* 预添加班级处理
* @return
*/
@RequestMapping("/preAddClass")
public ModelAndView preAddClass() {
logger.info("预添加班级信息");
ModelAndView model = new ModelAndView();
//获取年级信息
List<GradeInfo> grades = gradeInfoService.getGrades();
model.setViewName("admin/classedit");
model.addObject("grades", grades);
//获取不是班主任的教师
teacher.setIsWork(0);
Map<String, Object> map = new HashMap<String, Object>();
map.put("startIndex", null);
map.put("pageShow", null);
map.put("teacher", teacher);
List<TeacherInfo> teachers = teacherInfoService.getTeachers(map);
model.addObject("teachers", teachers);
model.addObject("editClass", new ClassInfo());
return model;
}
/**
* 添加班级
* @param classInfo 班级信息
* @param request
* @return
*/
@RequestMapping(value="/class", method=RequestMethod.POST)
public String isAddClass(ClassInfo classInfo, HttpServletRequest request) {
logger.info("添加班级信息 "+classInfo);
//修改教师班主任状态
String returnMsg = isChangeTeacherWork(1, classInfo.getTeacher().getTeacherId());
if (returnMsg != null) {
request.setAttribute("error", "修改教师班主任状态 对应教师编号有误");
return "error";
}
//添加
int row = classInfoService.isAddClass(classInfo);
if (row < 1) {
logger.error("班级 "+classInfo+" 删除失败");
request.setAttribute("error", "班级 "+classInfo.getClassName()+" 添加失败,请稍后再试!");
return "../error";
}
return "redirect:/classes";
}
/**
* 删除班级
* @param classId 班级编号
* @param request
* @return
*/
@RequestMapping(value="/del/class/{classId}", method=RequestMethod.DELETE)
public String isDelClass(@PathVariable("classId") Integer classId, HttpServletRequest request) {
logger.info("删除班级 "+classId);
//将删除班级对于之前班主任改为 非班主任状态
//需要在删除班级之前修改,如果先删除了班级,再根据班级获取教师编号,就不能获取
ClassInfo delClass = classInfoService.getClassById(classId);
String returnMsg = isChangeTeacherWork(0, delClass.getTeacher().getTeacherId());
if (returnMsg != null) {
request.setAttribute("error", "修改教师班主任状态 对应教师编号有误");
return "error";
}
//删除
int row = classInfoService.isDelClass(classId);
if (row < 1) {
logger.error("班级 "+classId+" 删除失败");
request.setAttribute("error", "班级删除失败,请稍后再试!");
return "../error";
}
return "redirect:/classes";
}
/**
* 预修改班级处理
* @param classId 班级编号
* @return
*/
@RequestMapping(value="edit/class/{classId}", method=RequestMethod.GET)
public ModelAndView preUpdateClass(@PathVariable("classId") Integer classId) {
logger.info("预修改班级处理");
ModelAndView model = new ModelAndView();
//获取要修改班级
ClassInfo classInfo = classInfoService.getClassById(classId);
model.setViewName("/admin/classedit");
model.addObject("editClass", classInfo);
List<GradeInfo> grades = gradeInfoService.getGrades();
//获取不是班主任的教师
teacher.setIsWork(0);
Map<String, Object> map = new HashMap<String, Object>();
map.put("startIndex", null);
map.put("pageShow", null);
map.put("teacher", teacher);
List<TeacherInfo> teachers = teacherInfoService.getTeachers(map);
//如果没有可用班主任
if (teachers.size() == 0 || teachers == null) {
teacher.setTeacherId(classInfo.getTeacher().getTeacherId());
teacher.setTeacherName("暂无剩余教师");
teachers.add(teacher);
}
model.addObject("teachers", teachers);
model.addObject("grades", grades);
return model;
}
/**
* 修改班级信息
* @param classInfo 班级信息
* @param request
* @param lastTeacherId 上一个班主任编号,修改其 班主任状态
* @return
*/
@RequestMapping(value="edit/class/class", method=RequestMethod.PUT)
public String isUpdateClass(ClassInfo classInfo, HttpServletRequest request,
@RequestParam(value="lastTeacher", required=false) Integer lastTeacherId) {
//修改上一教师不为班主任状态
if (lastTeacherId != null) {
String returnMsg = isChangeTeacherWork(0, lastTeacherId);
if (returnMsg != null) {
request.setAttribute("error", "修改教师班主任状态 对应教师编号有误");
return "/error";
}
}
//修改当前教师为班主任状态
String returnMsg = isChangeTeacherWork(1, classInfo.getTeacher().getTeacherId());
if (returnMsg != null) {
request.setAttribute("error", "修改教师班主任状态 对应教师编号有误");
return "/error";
}
logger.info("修改班级 "+classInfo);
int row = classInfoService.isUpdateClass(classInfo);
if (row < 1) {
logger.error("班级 "+classInfo+" 修改失败");
request.setAttribute("error", "班级修改失败,请稍后再试!");
return "../error";
}
return "redirect:/classes";
}
/**
* 获取指定年级下的班级
* @param gradeId 年级编号
* @param response
* @throws IOException
*/
@RequestMapping(value="/gradeclass/{gradeId}", method=RequestMethod.GET)
public void getClassesByGradeId(@PathVariable("gradeId") Integer gradeId,
HttpServletResponse response) throws IOException {
logger.info("获取年级 "+gradeId+" 下的班级集合");
List<ClassInfo> classes = classInfoService.getClassByGradeId(gradeId);
String json = gson.toJson(classes);
response.getWriter().print(json);
}
/**
* 修改教师(班主任)工作状态
* @param status 是否为班主任标识
* @param teacherId 教师编号
*/
private String isChangeTeacherWork(int status, Integer teacherId) {
logger.info("修改教师 "+teacherId+" 的状态为 "+status);
teacher.setIsWork(status);
if (teacherId == null) {
logger.error("修改教师班主任状态 对应教师编号有误");
return "修改教师班主任状态 对应教师编号有误";
}
teacher.setTeacherId(teacherId);
int row = teacherInfoService.updateTeacherIsWork(teacher);
return null;
}
@RequestMapping("/stuCount")
public void getStudentCountForClass(
@RequestParam(value="gradeId", required=false) Integer gradeId,
HttpServletResponse response) throws IOException {
Map<String, Object> map = classInfoService.getStudentCountForClass(gradeId);
String json = StudentCount.createBarJson(map);
response.getWriter().print(json);
}
/**
* 预添加班级处理
* @return
*/
@RequestMapping("/preStudentCount")
public ModelAndView preStudentCount() {
ModelAndView model = new ModelAndView();
//获取年级信息
List<GradeInfo> grades = gradeInfoService.getGrades();
model.setViewName("admin/charts/studentCount");
model.addObject("grades", grades);
return model;
}
}
年级信息
package com.taohan.online.exam.handler;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.google.gson.Gson;
import com.taohan.online.exam.po.GradeInfo;
import com.taohan.online.exam.service.GradeInfoService;
/**
*
* <p>Title: GradeInfoHandler</p>
* <p>Description: 年级</p>
* @author: taohan
* @date: 2018-8-14
* @time: 上午10:03:33
* @version: 1.0
*/
@Controller
public class GradeInfoHandler {
@Autowired
@Qualifier("gson")
private Gson gson;
@Autowired
private GradeInfoService gradeInfoService;
private Logger logger = Logger.getLogger(GradeInfoHandler.class);
/**
* 获取所有年级集合
* @return
*/
@RequestMapping(value="/grades")
public ModelAndView getGrades() {
logger.info("获取所有年级");
ModelAndView model = new ModelAndView();
model.setViewName("admin/grades");
//获取所有年级
List<GradeInfo> grades = gradeInfoService.getGrades();
model.addObject("grades", grades);
return model;
}
/**
* 预添加年级处理
* @param map
* @return
*/
@RequestMapping("/preAddGrade")
public String preAddGrade(Map<String, Object> map) {
logger.info("年级添加预处理");
map.put("grade", new GradeInfo());
return "admin/gradeedit";
}
/**
* 添加年级
* @param grade
* @param request
* @return
*/
@RequestMapping(value="/grade", method=RequestMethod.POST)
public String isAddGrade(GradeInfo grade, HttpServletRequest request) {
logger.info("添加年级 "+grade);
if (grade == null) {
logger.error("年级 "+grade+" 为空");
request.setAttribute("error", "年级添加失败,请稍后再试!");
return "error";
}
int row = gradeInfoService.isAddGrade(grade);
if (row < 1) {
logger.error("年级添加失败");
request.setAttribute("error", "年级添加失败,请稍后再试!");
return "error";
}
return "redirect:grades";
}
/**
* 预修改年级处理
* @param gradeId 待修改年级编号
* @param map
* @return
*/
@RequestMapping(value="/grade/update/{gradeId}", method=RequestMethod.GET)
public String preUpdateGrade(@PathVariable("gradeId") Integer gradeId,
Map<String, Object> map) {
logger.info("年级修改预处理");
map.put("grade", gradeInfoService.getGradeById(gradeId));
return "/admin/gradeedit";
}
/**
* 修改年级信息
* @param grade
* @param request
* @return
*/
@RequestMapping(value="/grade/update/grade", method=RequestMethod.PUT)
public String isUpdateGrade(GradeInfo grade, HttpServletRequest request) {
logger.info("修改年级 "+grade+" 的信息");
int row = gradeInfoService.isUpdateGrade(grade);
if (row < 1) {
logger.error("年级修改失败");
request.setAttribute("error", "年级修改失败,请稍后再试!");
return "/error";
}
return "redirect:/grades";
}
/**
* 删除年级
* @param gradeId
* @param request
* @return
*/
@RequestMapping(value="grade/del/{gradeId}", method=RequestMethod.DELETE)
public String isDelGrade(@PathVariable("gradeId") Integer gradeId, HttpServletRequest request) {
logger.info("删除年级 "+gradeId);
int row = gradeInfoService.isDelGrade(gradeId);
if (row < 1) {
logger.error("年级删除失败");
request.setAttribute("error", "年级删除失败,请稍后再试!");
return "/error";
}
return "redirect:/grades";
}
}
如果也想学习本系统,下面领取。回复:198ssm