Java毕业设计实战之在线高中考试系统的实现

作者:qq_1334611189 时间:2021-07-04 06:15:20 

项目分为前台和后台,前台主要为学生角色、后台主要为管理员角色。

管理员添加试题和发布试卷,学生负责在线考试、在线查看成绩和错题记录列表等。

管理员功能有:年级管理、课程管理、试题管理、试卷管理、学生管理等。

运行环境:jdk1.8、mysql5.x、eclipse、tomcat8.5\7.0、maven3.5\3.6。

Java毕业设计实战之在线高中考试系统的实现

Java毕业设计实战之在线高中考试系统的实现

Java毕业设计实战之在线高中考试系统的实现

Java毕业设计实战之在线高中考试系统的实现

Java毕业设计实战之在线高中考试系统的实现

Java毕业设计实战之在线高中考试系统的实现

统一管理学生 教师 管理员信息:


/**
* 统一管理学生 教师 管理员信息
*/
@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<>();
   }
}

来源:https://blog.csdn.net/m0_59687645/article/details/122209116

标签:Java,考试系统,毕业设计
0
投稿

猜你喜欢

  • 一篇文章带你从java字节码层理解i++和++i

    2023-05-29 13:57:58
  • Intellij IDEA + Android SDK + Genymotion Emulator打造最佳Android开发环境

    2023-06-17 06:47:11
  • 如何使用Java redis实现发送手机验证码功能

    2023-11-26 17:25:00
  • 解析Java实现随机验证码功能的方法详解

    2022-09-25 23:26:14
  • springmvc后台基于@ModelAttribute获取表单提交的数据

    2023-08-05 12:29:35
  • 如何解决Spring in action @valid验证不生效的问题

    2023-08-29 07:59:56
  • 详解Java中的实例初始化块(IIB)

    2023-06-08 08:35:46
  • Java反射获取class对象方式解析

    2023-04-22 15:51:30
  • C#语言主要语言区域

    2021-10-05 13:58:38
  • JAVA中数组从小到大排序的2种方法实例

    2021-10-09 09:46:18
  • Java操作Mongodb数据库实现数据的增删查改功能示例

    2023-11-25 00:02:05
  • javac -encoding 用法详解

    2022-06-28 08:58:08
  • Java实现超大Excel文件解析(XSSF,SXSSF,easyExcel)

    2023-11-27 11:02:17
  • java开发工作中对InheritableThreadLocal使用思考

    2023-11-24 21:46:44
  • java原生序列化和Kryo序列化性能实例对比分析

    2023-11-26 16:04:20
  • Seata AT模式如何实现行锁详解

    2022-11-18 23:43:34
  • idea 有时提示找不到类或者符号的解决

    2023-11-29 04:10:43
  • 总结一次C++ 程序优化历程

    2023-11-02 22:38:30
  • maven的pom文件与打包详解

    2023-12-24 00:23:51
  • SpringBoot 使用 FTP 操作文件的过程(删除、上传、下载文件)

    2021-07-26 10:40:05
  • asp之家 软件编程 m.aspxhome.com