Java毕业设计实战之在线高中考试系统的实现
更新时间:2022年2月5日 20:31 点击:192 作者:qq_1334611189
项目分为前台和后台,前台主要为学生角色、后台主要为管理员角色。
管理员添加试题和发布试卷,学生负责在线考试、在线查看成绩和错题记录列表等。
管理员功能有:年级管理、课程管理、试题管理、试卷管理、学生管理等。
运行环境:jdk1.8、mysql5.x、eclipse、tomcat8.5\7.0、maven3.5\3.6。
统一管理学生 教师 管理员信息:
/** * 统一管理学生 教师 管理员信息 */ @RestController public class UserController { @Resource(name = "userService") private IUserService userService; /** * 查询用户信息 * 先判断用户类型 在查询用户信息 */ @RequestMapping(value = "/user/qryUserInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public Result<User> qryUserInfo() { return userService.qryUserInfo(); } /** * 更新用户信息 */ @RequestMapping(value = "/user/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public Result<User> update(HttpRequest request) { User user = new User(); user.setUserId(request.getString("user_id")); user.setName(request.getString("name")); user.setSex(request.getInteger("sex")); user.setType(User.UserType.get(request.getInteger("type"))); return userService.update(user, ImageUtil.stringToBytes(request.getString("user_image"))); } /** * 更新用户密码 */ @RequestMapping(value = "/user/updatePwd", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public Result<User> updatePwd(HttpRequest request) { return userService.updatePwd(request.getString("old_pwd"), request.getString("pwd")); } }
管理员控制器:
/** * 管理员控制器 */ @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 = "/admin/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.admin}) public Result<Admin> update(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.update(admin, ImageUtil.stringToBytes(request.getString("admin_image"))); } /** * 管理员 删除管理员 */ @RequestMapping(value = "/admin/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.admin}) public Result<Admin> del(HttpRequest request) { List<String> adminIdList = new ArrayList<>(); JSONArray array = request.getJSONArray("admin_id_list"); for (int i = 0; i < array.size(); i++) { adminIdList.add(array.getString(i)); } return adminService.del(adminIdList); } }
考试管理控制器:
/** * 考试管理控制器 */ @RestController public class ExamInfoController { @Resource(name = "examInfoService") private IExamInfoService examInfoService; /** * 教师 查询考试列表 */ @RequestMapping(value = "/examinfo/qryPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public ListResult<ExamInfo> exam(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; return examInfoService.qryPage(param, pageNo, pageSize); } /** * 教师 添加新的考试信息 */ @RequestMapping(value = "/examinfo/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public Result<ExamInfo> insert(HttpRequest request) { ExamInfo exam = new ExamInfo(); exam.setTestPaperId(request.getInteger("test_paper_id")); exam.setClassId(request.getString("class_id")); exam.setState(1); exam.setTime(request.getInteger("time")); exam.setEffTime(DateUtils.toDate(request.getString("eff_time"), DateConst.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI)); exam.setExpTime(DateUtils.toDate(request.getString("exp_time"), DateConst.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI)); exam.setUpdateTime(new Date()); return examInfoService.insert(exam); } /** * 教师 更新考试信息 */ @RequestMapping(value = "/examinfo/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public Result<ExamInfo> update(HttpRequest request) { ExamInfo exam = new ExamInfo(); exam.setExamId(request.getInteger("exam_id")); exam.setTestPaperId(request.getInteger("test_paper_id")); exam.setClassId(request.getString("class_id")); exam.setState(1); exam.setTime(request.getInteger("time")); exam.setEffTime(DateUtils.toDate(request.getString("eff_time"), DateConst.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI)); exam.setExpTime(DateUtils.toDate(request.getString("exp_time"), DateConst.DATE_TIME_FORMAT_YYYY_MM_DD_HH_MI)); exam.setUpdateTime(new Date()); exam.setUpdateTime(new Date()); return examInfoService.update(exam); } /** * 教师 新建状态的考试信息可以删除 */ @RequestMapping(value = "/examinfo/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public Result<ExamInfo> del(HttpRequest request) { List<Integer> examIdList = new ArrayList<>(); JSONArray array = request.getJSONArray("exam_id_list"); for (int i = 0; i < array.size(); i++) { examIdList.add(array.getInteger(i)); } return examInfoService.del(examIdList); } /** * 教师 发布考试信息 */ @RequestMapping(value = "/examinfo/release", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public Result<ExamInfo> updateState(HttpRequest request) { return examInfoService.release(request.getInteger("exam_id")); } /** * 学生 查询考试试题分组列表 */ @RequestMapping(value = "/examinfo/qryExamQueGroupList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.student, RoleEnum.teacher}) public Result<TestPaperQuestionGroup> qryExamQueGroupList(HttpRequest request) { return examInfoService.qryExamQueGroupList(request.getInteger("exam_id")); } /** * 学生 查询考试试题列表 */ @RequestMapping(value = "/examinfo/qryExamQuestionList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.student}) public Result<StudentExamQuestionRecord> qryExamQuestionList(HttpRequest request) { return examInfoService.qryExamQuestionList(request.getInteger("exam_id"), request.getString("student_id"), request.getInteger("question_group_id")); } /** * 教师 判卷查询试题列表 */ @RequestMapping(value = "/examinfo/qryMarkQueList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public Result<StudentExamQuestionRecord> qryMarkQueList(HttpRequest request) { return examInfoService.qryMarkQueList(request.getInteger("exam_id"), request.getString("student_id"), request.getInteger("question_group_id")); } /** * 教师 记录学生考试分数 complete */ @RequestMapping(value = "/examinfo/updateQueScore", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public Result<ExamInfo> updateQueScore(HttpRequest request) { StudentExamQuestionRecord record = new StudentExamQuestionRecord(); record.setExamId(request.getInteger("exam_id")); record.setStudentId(request.getString("student_id")); record.setQuestionGroupId(request.getInteger("question_group_id")); record.setQuestionId(request.getLong("question_id")); record.setScore(request.getFloat("score")); record.setCorrect(request.getBoolean("correct")); return examInfoService.updateQueScore(record); } /** * 教师 完成评分 */ @RequestMapping(value = "/examinfo/complete", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.teacher}) public Result<ExamInfo> complete(HttpRequest request) { return examInfoService.complete(request.getInteger("exam_id"), request.getString("student_id")); } }
登录控制层:
@RestController public class LoginController { @Resource(name = "loginService") private ILoginService loginService; /** * 用户登录调用 在登陆成功生成两个token 同时返回各自首页 * * 学生 student/student * * 老师 teacher/teacher * * 管理员 admin/admin */ @RequestMapping(value = "/login/login", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public Result<Token> login(HttpRequest request) { return loginService.login(request.getString("login_name"), request.getString("pwd")); } /** * 登录检查 */ @RequestMapping(value = "/login/check", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public Result<Token> check() { return new Result<>(); } /** * token 续约 */ @RequestMapping(value = "/login/refresh", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public Result<Token> refresh(HttpRequest request) { String refreshToken = request.getString("refresh_token"); String urlId = request.getString("url_id"); Token token = TokenCache.getInstance().get(urlId); if(token == null){ ExceptionHelper.error(ErrorCode.ERROR_CODE_0003); } try { Claims claims = TokenUtils.parseToken(refreshToken); if (StringUtils.isNotEmpty((String.valueOf(claims.getOrDefault("student_id", ""))))) { claims.put("student_id", SessionContext.get("student_id")); } 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<>(); } }
到此这篇关于Java毕业设计实战之在线高中考试系统的实现的文章就介绍到这了,更多相关Java 考试系统内容请搜索猪先飞以前的文章或继续浏览下面的相关文章希望大家以后多多支持猪先飞!
原文出处:https://blog.csdn.net/m0_59687645/article/details/122209116
相关文章
- 这篇文章主要介绍了如何利用java语言实现经典《复杂迷宫》游戏,文中采用了swing技术进行了界面化处理,感兴趣的小伙伴可以动手试一试...2022-02-01
java 运行报错has been compiled by a more recent version of the Java Runtime
java 运行报错has been compiled by a more recent version of the Java Runtime (class file version 54.0)...2021-04-01- 这篇文章主要介绍了在java中获取List集合中最大的日期时间操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-15
- 这篇文章主要介绍了教你怎么用Java获取国家法定节假日,文中有非常详细的代码示例,对正在学习java的小伙伴们有非常好的帮助,需要的朋友可以参考下...2021-04-23
- 这篇文章主要介绍了Java如何发起http请求的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-31
- 说起C#和Java这两门语言(语法,数据类型 等),个人以为,大概有90%以上的相似,甚至可以认为几乎一样。但是在工作中,我也发现了一些细微的差别...2020-06-25
- 这篇文章主要介绍了解决Java处理HTTP请求超时的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-29
- 这篇文章主要介绍了java 判断两个时间段是否重叠的案例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-15
- 这篇文章主要介绍了超简洁java实现双色球若干注随机号码生成(实例代码),本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-04-02
- 这篇文章主要介绍了Java生成随机姓名、性别和年龄的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-10-01
java 画pdf用itext调整表格宽度、自定义各个列宽的方法
这篇文章主要介绍了java 画pdf用itext调整表格宽度、自定义各个列宽的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-01-31- 这篇文章主要介绍了java正则表达式判断前端参数修改表中另一个字段的值,需要的朋友可以参考下...2021-05-07
Java使用ScriptEngine动态执行代码(附Java几种动态执行代码比较)
这篇文章主要介绍了Java使用ScriptEngine动态执行代码,并且分享Java几种动态执行代码比较,需要的朋友可以参考下...2021-04-15- 这篇文章主要介绍了Java开发实现人机猜拳游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-08-03
- 这篇文章主要介绍了Java List集合返回值去掉中括号('[ ]')的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-08-29
Java中lombok的@Builder注解的解析与简单使用详解
这篇文章主要介绍了Java中lombok的@Builder注解的解析与简单使用,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-01-06- 下面小编就为大家带来一篇java中String类型变量的赋值问题介绍。小编觉得挺不错的。现在分享给大家,给大家一个参考。...2016-03-28
Java 8 Stream 的终极技巧——Collectors 功能与操作方法详解
这篇文章主要介绍了Java 8 Stream Collectors 功能与操作方法,结合实例形式详细分析了Java 8 Stream Collectors 功能、操作方法及相关注意事项,需要的朋友可以参考下...2020-05-20- 这篇文章主要介绍了Java线程池中的各个参数如何合理设置操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-06-19
- 在Java中,我们可以利用多线程来最大化地压榨CPU多核计算的能力,下面这篇文章主要给大家介绍了关于java中多线程与线程池基本使用的相关资料,需要的朋友可以参考下...2021-09-13