基于javaweb+mysql的springboot在线考试系统(单选,多选,判断,填空,简答题)(java+springboot+ssm+mysql+html+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
有三种角色:老师、学生、管理员
基于javaweb的SpringBoot在线考试系统(单选,多选,判断,填空,简答题)(java+springboot+ssm+mysql+html+maven)
功能:
学生信息 班级 专业 学号 姓名 在线考试 成绩查询 个人信息 密码修改 教师管理 教师编号 姓名 所教科目 题库管理 单选题 多选题 填空题 判断题,简答题(人工阅卷) 试卷管理 新建试卷 在试库中选择试题 试卷设置 发布试卷 考试管理 发布考试计划 学生考试 自动阅卷 人工阅卷 个人信息 密码修改 管理员 学生管理 教师管理 管理员管理 院系管理 班级管理 个人信息 密码修改。
/**
* 试卷控制器
*/
@RestController
public class TestPaperController {
@Resource(name = "testPaperService")
private ITestPaperService testPaperService;
/**
* 分页查询试卷信息
*/
@RequestMapping(value = "/testpaper/qryPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public ListResult<TestPaper> qryPage(HttpRequest request) {
int pageNo = request.containsKey("page_no") ? request.getInteger("page_no") : 1;
int pageSize = request.containsKey("page_size") ? request.getInteger("page_size") : 20;
String testPaperName = request.getString("test_paper_name");
String academicsId = request.getString("academics_id");
return testPaperService.qryPage(testPaperName, academicsId, pageNo, pageSize);
}
/**
* 教师 更新新试卷
*/
@RequestMapping(value = "/testpaper/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public Result<TestPaper> insert(HttpRequest request) {
return testPaperService.insert(request.getString("test_paper_name"), request.getString("academics_id"));
}
/**
* 教师 删除试卷
*/
@RequestMapping(value = "/testpaper/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public Result<TestPaper> del(HttpRequest request) {
List<Integer> testPaperIdList = new ArrayList<>();
JSONArray array = request.getJSONArray("test_paper_id_list");
for (int i = 0; i < array.size(); i++) {
testPaperIdList.add(array.getInteger(i));
public Result<Department> update(HttpRequest request) {
Department department = new Department();
department.setDepartmentId(request.getString("department_id"));
department.setDepartmentName(request.getString("department_name"));
department.setUpdateTime(new Date());
return departmentService.update(department);
}
/**
* 管理员 删除院系
*/
@RequestMapping(value = "/department/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<Department> del(HttpRequest request) {
List<String> departmentIdList = new ArrayList<>();
JSONArray array = request.getJSONArray("department_id_list");
for (int i = 0; i < array.size(); i++) {
departmentIdList.add(array.getString(i));
}
return departmentService.del(departmentIdList);
}
}
/**
* 管理员控制器
*/
@RestController
public class AdminController {
unFilter = new HashSet<>(100);
unFilter.add("/");
unFilter.add("/login");
// 管理员相关界面
unFilter.add("/admin/admin/");
unFilter.add("/admin/index/");
unFilter.add("/admin/studentmanage/");
unFilter.add("/admin/teachermanage/");
unFilter.add("/admin/adminmanage/");
unFilter.add("/admin/departmentmanage/");
unFilter.add("/admin/classinfomanage/");
unFilter.add("/admin/academicsmanage/");
// 教师相关界面
unFilter.add("/teacher/teacher/");
unFilter.add("/teacher/index/");
unFilter.add("/teacher/questionmanage/");
unFilter.add("/teacher/testpapermanage/");
unFilter.add("/teacher/testpaperedit/");
unFilter.add("/teacher/examinfomanage/");
// 学生相关界面
unFilter.add("/student/student/");
unFilter.add("/student/index/");
unFilter.add("/student/onlineexam/");
unFilter.add("/student/scoreinquiry/");
//公共界面
unFilter.add("/common/userinfomanage");// 个人资料修改
unFilter.add("/common/pwdmanage");// 密码修改
// 不升级请求
unUpgradeRequest = new HashSet<>(100);
unUpgradeRequest.add("upload");
//升级请求不验证请求
upgradeRequest = new HashSet<>(100);
upgradeRequest.add("/login/login");
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
if (req instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
String url = request.getRequestURI();
String suffix = getSuffix(url);
//过滤请求
if (suffixs.contains(suffix)) {
chain.doFilter(request, response);
return;
}
//过滤请求
if (unFilter.contains(url)) {
chain.doFilter(request, response);
SessionContext.clean();
return;
}
}
@RequestMapping(value = "/teacher/studentpapers/{url_id}/{exam_id}/{student_id}")
public String studentpapers(@PathVariable(value = "url_id") String urlId,
@PathVariable(value = "exam_id") String examId,
@PathVariable(value = "student_id") String studentId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
model.addAttribute("exam_id", examId);
model.addAttribute("student_id", studentId);
studentExamRecordService.studentpapers(Integer.parseInt(examId), studentId, model);
return "teacher/studentpapers/studentpapers";
}
}
/**
* 试题控制器
*/
@RestController
public class QuestionController {
return "admin/admin";
}
/**
* 管理员 首页
*/
@RequestMapping(value = "/admin/index/{url_id}")
public String index(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
return "admin/index";
}
/**
* 管理员 学生管理界面
*/
@RequestMapping(value = "/admin/studentmanage/{url_id}")
public String studentmanage(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
return "admin/studentmanage/studentmanage";
}
/**
* 管理员 教师管理界面
*/
@RequestMapping(value = "/admin/teachermanage/{url_id}")
public String teachermanage(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
return "admin/teachermanage/teachermanage";
}
/**
* 管理员 管理员管理界面
*/
@RequestMapping(value = "/admin/adminmanage/{url_id}")
studentExamRecordService.markpapers(Integer.parseInt(examId), model);
return "teacher/markpapers/markpapers";
}
@RequestMapping(value = "/teacher/studentpapers/{url_id}/{exam_id}/{student_id}")
public String studentpapers(@PathVariable(value = "url_id") String urlId,
@PathVariable(value = "exam_id") String examId,
@PathVariable(value = "student_id") String studentId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
model.addAttribute("exam_id", examId);
model.addAttribute("student_id", studentId);
studentExamRecordService.studentpapers(Integer.parseInt(examId), studentId, model);
return "teacher/studentpapers/studentpapers";
}
}
/**
* 试题控制器
*/
@RestController
public class QuestionController {
@RequestMapping(value = "/teacher/testpaperedit/{url_id}/{test_paper_id}")
public String examplanmanage(@PathVariable(value = "url_id") String urlId, @PathVariable(value = "test_paper_id") String testPaperId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
testPaperService.qryByTestPaperId(Integer.parseInt(testPaperId), model);
return "teacher/testpapermanage/testpaperedit";
}
/**
* 教师 考试管理
*/
@RequestMapping(value = "/teacher/examinfomanage/{url_id}")
public String examplanmanage(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
return "teacher/examinfomanage/examinfomanage";
}
/**
* 教师 阅卷成绩查看
*/
@RequestMapping(value = "/teacher/markpapers/{url_id}/{exam_id}")
public String markpapers(@PathVariable(value = "url_id") String urlId,
@PathVariable(value = "exam_id") String examId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
studentExamRecordService.markpapers(Integer.parseInt(examId), model);
return "teacher/markpapers/markpapers";
}
@RequestMapping(value = "/teacher/studentpapers/{url_id}/{exam_id}/{student_id}")
public String studentpapers(@PathVariable(value = "url_id") String urlId,
@PathVariable(value = "exam_id") String examId,
@PathVariable(value = "student_id") String studentId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
model.addAttribute("exam_id", examId);
model.addAttribute("student_id", studentId);
studentExamRecordService.studentpapers(Integer.parseInt(examId), studentId, model);
return "teacher/studentpapers/studentpapers";
}
}
/**
* 教师班级科目关系 控制器
*/
@RestController
public class TeacherClassRefController {
@Resource(name = "teacherClassRefService")
private ITeacherClassRefService teacherClassRefService;
/**
* 管理员 查询班级所学科目和任教教师列表
*/
@RequestMapping(value = "/teacherclassref/qryByClassId", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public ListResult<TeacherClassRef> qryByClassId(HttpRequest request) {
return teacherClassRefService.qryByClassId(request.getString("class_id"));
}
/**
* 管理员 添加班级所学科目任教教师
*/
@RequestMapping(value = "/teacherclassref/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<TeacherClassRef> insert(HttpRequest request) {
TeacherClassRef teacherClassRef = new TeacherClassRef();
teacherClassRef.setClassId(request.getString("class_id"));
teacherClassRef.setAcademicsId(request.getString("academics_id"));
teacherClassRef.setTeacherId(request.getString("teacher_id"));
return teacherClassRefService.insert(teacherClassRef);
}
/**
* 管理员 删除班级所学科目任教教师
*/
@RequestMapping(value = "/teacherclassref/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<TeacherClassRef> del(HttpRequest request) {
TeacherClassRef teacherClassRef = new TeacherClassRef();
teacherClassRef.setClassId(request.getString("class_id"));
teacherClassRef.setAcademicsId(request.getString("academics_id"));
teacherClassRef.setTeacherId(request.getString("teacher_id"));
return teacherClassRefService.del(teacherClassRef);
/**
* 管理员 更新教师属性
*/
@RequestMapping(value = "/teacher/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<Teacher> update(HttpRequest request) {
Teacher teacher = new Teacher();
teacher.setTeacherId(request.getString("teacher_id"));
teacher.setName(request.getString("teacher_name"));
teacher.setPwd(request.getString("teacher_id"));
teacher.setSex(request.getInteger("sex"));
teacher.setUpdateTime(new Date());
return teacherService.update(teacher, ImageUtil.stringToBytes(request.getString("teacher_image")));
}
/**
* 管理员 删除教师
*/
@RequestMapping(value = "/teacher/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<Teacher> del(HttpRequest request) {
List<String> teacherIdList = new ArrayList<>();
JSONArray array = request.getJSONArray("teacher_id_list");
for (int i = 0; i < array.size(); i++) {
teacherIdList.add(array.getString(i));
}
return teacherService.del(teacherIdList);
}
/**
* 管理员 查询所有任教老师
*/
@RequestMapping(value = "/teacher/qryAllList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public ListResult<Teacher> qryAllList() {
return teacherService.qryAllList();
}
}
/**
* 教师 题库管理
*/
@RequestMapping(value = "/teacher/questionmanage/{url_id}")
public String questionmanage(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
return "teacher/questionmanage/questionmanage";
}
/**
* 教师 试卷管理
*/
@RequestMapping(value = "/teacher/testpapermanage/{url_id}")
public String testpapermanage(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
return "teacher/testpapermanage/testpapermanage";
}
/**
* 教师 试卷编辑
*/
@RequestMapping(value = "/teacher/testpaperedit/{url_id}/{test_paper_id}")
public String examplanmanage(@PathVariable(value = "url_id") String urlId, @PathVariable(value = "test_paper_id") String testPaperId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
testPaperService.qryByTestPaperId(Integer.parseInt(testPaperId), model);
return "teacher/testpapermanage/testpaperedit";
}
/**
* 教师 考试管理
*/
@RequestMapping(value = "/teacher/examinfomanage/{url_id}")
public String examplanmanage(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
/**
* 管理员控制器
*/
@RestController
public class AdminController {
@Resource(name = "adminService")
private IAdminService adminService;
/**
* 管理员 查询管理员列表
*/
@RequestMapping(value = "/admin/qryPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public ListResult<Admin> qryPage(HttpRequest request) {
Map<String, Object> param = new HashMap<>();
int pageNo = request.containsKey("page_no") ? request.getInteger("page_no") : 1;
int pageSize = request.containsKey("page_size") ? request.getInteger("page_size") : 20;
if (request.containsKey("login_name")) {
param.put("login_name", request.getString("login_name"));
}
if (request.containsKey("name")) {
param.put("name", request.getString("name"));
}
return adminService.qryPage(param, pageNo, pageSize);
}
/**
* 管理员 添加管理员
*/
@RequestMapping(value = "/admin/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public Result<Admin> insert(HttpRequest request) {
Admin admin = new Admin();
admin.setLoginName(request.getString("login_name"));
admin.setName(request.getString("admin_name"));
admin.setPwd(request.getString("login_name"));
admin.setSex(request.getInteger("sex"));
admin.setUpdateTime(new Date());
return adminService.insert(admin, ImageUtil.stringToBytes(request.getString("admin_image")));
}
/**
* 教师 查询试题分组试题列表
*/
@RequestMapping(value = "/testpaper/qryQueByQueGroupId", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public ListResult<TestPaperQuestionRef> qryQueByQueGroupId(HttpRequest request) {
return testPaperService.qryQueByQueGroupId(request.getInteger("test_paper_id"), request.getInteger("question_group_id"));
}
/**
* 教师查询所教授科目的试卷列表
*/
@RequestMapping(value = "/testpaper/qryListByTeacherId", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public ListResult<TestPaper> qryListByTeacherId() {
return testPaperService.qryListByTeacherId();
}
}
/**
* 教师 相关界面
*/
@Controller
public class TeacherHtmlController {
@Resource(name = "testPaperService")
private ITestPaperService testPaperService;
@Resource(name = "studentExamRecordService")
private IStudentExamRecordService studentExamRecordService;
/**
* 教师界面 teacher/teacher.html
*/
return testPaperService.qryPage(testPaperName, academicsId, pageNo, pageSize);
}
/**
* 教师 更新新试卷
*/
@RequestMapping(value = "/testpaper/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public Result<TestPaper> insert(HttpRequest request) {
return testPaperService.insert(request.getString("test_paper_name"), request.getString("academics_id"));
}
/**
* 教师 删除试卷
*/
@RequestMapping(value = "/testpaper/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public Result<TestPaper> del(HttpRequest request) {
List<Integer> testPaperIdList = new ArrayList<>();
JSONArray array = request.getJSONArray("test_paper_id_list");
for (int i = 0; i < array.size(); i++) {
testPaperIdList.add(array.getInteger(i));
}
return testPaperService.del(testPaperIdList);
}
/**
* 教师 更新状态
*/
@RequestMapping(value = "/testpaper/updateState", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public Result<TestPaper> updateState(HttpRequest request) {
return testPaperService.updateState(request.getInteger("test_paper_id"), request.getInteger("state"));
}
/**
* 教师 试卷编辑
*/
@RequestMapping(value = "/testpaper/edit", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.teacher})
public Result<TestPaper> edit(HttpRequest request) {
TestPaper testPaper = new TestPaper();
testPaper.decode(request.getJson());
return testPaperService.edit(testPaper);
}
/**
* 学生 相关界面
*/
@Controller
public class StudentHtmlController {
@Resource(name = "studentService")
private IStudentService studentService;
/**
* 学生界面 student/student.html
*/
@RequestMapping(value = "/student/student/{url_id}")
public String student(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
return "student/student";
}
/**
* 学生界面 首页
*/
@RequestMapping(value = "/student/index/{url_id}")
public String index(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
studentService.index(model);
return "student/index";
}
/**
* 学生界面 在线考试
*/
@RequestMapping(value = "/student/onlineexam/{url_id}")
public String onlineexam(@PathVariable(value = "url_id") String urlId, Model model) {
if (!ValidateUrlIdUtil.validate(urlId, model)) {
return "error/error";
}
if (StringUtils.isNotEmpty((String.valueOf(claims.getOrDefault("teacher_id", ""))))) {
claims.put("teacher_id", SessionContext.get("teacher_id"));
}
if (StringUtils.isNotEmpty((String.valueOf(claims.getOrDefault("login_name", ""))))) {
claims.put("login_name", SessionContext.get("login_name"));
}
claims.put("name", claims.get("name"));
token.setToken(TokenUtils.createToken(claims, TokenUtils.expireTime));
token.setRefreshToken(TokenUtils.createToken(claims, TokenUtils.long_expireTime));
TokenCache.getInstance().add(token);
} catch (Exception e) {
ExceptionHelper.error(ErrorCode.ERROR_CODE_0003);
}
return new Result<>(token);
}
/**
* 退出系统
*/
@RequestMapping(value = "/login/exit", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public Result<Token> exit(HttpRequest request) {
String urlId = request.getString("url_id");
if (StringUtils.isNotEmpty(urlId)) {
TokenCache.getInstance().remove(urlId);
}
return new Result<>();
}
}
/**
* 管理员 相关界面
*/
@Controller
public class AdminHtmlController {
/**
* 管理员界面 admin/admin.html
*/
@RequestMapping(value = "/admin/admin/{url_id}")
try {
Claims claims = TokenUtils.parseToken(token);
SessionContext.set("student_id", claims.getOrDefault("student_id", ""));
SessionContext.set("teacher_id", claims.getOrDefault("teacher_id", ""));
SessionContext.set("login_name", claims.getOrDefault("login_name", ""));
SessionContext.set("name", claims.get("name"));
SessionContext.set("refresh_token", TokenUtils.shouldTokenRefresh(claims.getIssuedAt(), TokenUtils.expireTime));
} catch (Exception e) {
SessionContext.clean();
log.info("过滤url:{}", "session 过期");
ExceptionHelper.error(response, ErrorCode.ERROR_CODE_0003);
return;
}
}
// 不升级请求
if (unUpgradeRequest.contains(url)) {
chain.doFilter(request, response);
SessionContext.clean();
return;
}
HttpRequest httpRequest = new HttpRequest(request);
chain.doFilter(httpRequest, response);
SessionContext.clean();
}
}
private String getToken(HttpServletRequest request) {
String token = request.getHeader("token");
if (StringUtils.isEmpty(token)) {
token = request.getParameter("token");
}
return token;
}
private String getSuffix(String url) {
int index;
if ((index = url.lastIndexOf(".")) > 0) {
return url.substring(index + 1);
} else {
return null;
}
}
}
}
}
/**
* 班级信息控制器
*/
@RestController
public class ClassInfoController {
@Resource(name = "classInfoService")
private IClassInfoService classInfoService;
/**
* 查询院系的班级列表
*/
@RequestMapping(value = "/classinfo/qryByDepartmentId", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public ListResult<ClassInfo> qryByDepartmentId(HttpRequest request) {
return classInfoService.qryByDepartmentId(request.getString("department_id"));
}
/**
* 管理员 查询班级信息列表
*/
@RequestMapping(value = "/classinfo/qryPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@RoleAnnotation(types = {RoleEnum.admin})
public ListResult<ClassInfo> qryPage(HttpRequest request) {
Map<String, Object> param = new HashMap<>();
int pageNo = request.containsKey("page_no") ? request.getInteger("page_no") : 1;
int pageSize = request.containsKey("page_size") ? request.getInteger("page_size") : 20;
if (request.containsKey("class_id")) {
param.put("class_id", request.getString("class_id"));
}
if (request.containsKey("class_name")) {
param.put("class_name", request.getString("class_name"));
}
return classInfoService.qryPage(param, pageNo, pageSize);
}