您好,登錄后才能下訂單哦!
本篇內容主要講解“Java如何實現考試管理系統”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Java如何實現考試管理系統”吧!
本系統功能包括:
支持單選題、多選題、判斷題支持學生(student)、教師(teacher)、管理員(admin)三種角色學生:參加考試和查看我的考試教師:學生的所有權限+創建/編輯題目+創建/編輯考試管理員:教師的所有權限+管理用戶。
環境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
Springboot + Maven + Jpa+ Vue 等等組成,B/S模式 + Maven管理等等。
登錄控制層:
@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<>(); } }
統一管理學生 教師 管理員信息:
/** * 統一管理學生 教師 管理員信息 */ @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 StudentController { @Resource(name = "studentService") private IStudentService studentService; /** * 管理員 查詢學生列表 */ @RequestMapping(value = "/student/qryPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.admin}) public ListResult<Student> 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("student_id")) { param.put("student_id", request.getString("student_id")); } if (request.containsKey("name")) { param.put("name", request.getString("name")); } return studentService.qryPage(param, pageNo, pageSize); } @RequestMapping(value = "/student/add", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.admin}) public Result<Student> insert(HttpRequest request) { Student student = new Student(); student.setStudentId(request.getString("student_id")); student.setName(request.getString("student_name")); student.setPwd(request.getString("student_id")); student.setSex(request.getInteger("sex")); student.setClassId(request.getString("class_id")); student.setUpdateTime(new Date()); return studentService.insert(student, ImageUtil.stringToBytes(request.getString("student_image"))); } @RequestMapping(value = "/student/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.admin}) public Result<Student> update(HttpRequest request) { Student student = new Student(); student.setStudentId(request.getString("student_id")); student.setName(request.getString("student_name")); student.setPwd(request.getString("student_id")); student.setSex(request.getInteger("sex")); student.setClassId(request.getString("class_id")); student.setUpdateTime(new Date()); return studentService.update(student, ImageUtil.stringToBytes(request.getString("student_image"))); } @RequestMapping(value = "/student/del", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @RoleAnnotation(types = {RoleEnum.admin}) public Result<Student> del(HttpRequest request) { List<String> studentIdList = new ArrayList<>(); JSONArray array = request.getJSONArray("student_id_list"); for (int i = 0; i < array.size(); i++) { studentIdList.add(array.getString(i)); } return studentService.del(studentIdList); } }
到此,相信大家對“Java如何實現考試管理系統”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。