溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)

發(fā)布時(shí)間:2022-03-04 09:42:28 來(lái)源:億速云 閱讀:102 作者:小新 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要介紹了Java如何實(shí)現(xiàn)在線高中考試系統(tǒng),具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

項(xiàng)目分為前臺(tái)和后臺(tái),前臺(tái)主要為學(xué)生角色、后臺(tái)主要為管理員角色。

管理員添加試題和發(fā)布試卷,學(xué)生負(fù)責(zé)在線考試、在線查看成績(jī)和錯(cuò)題記錄列表等。

管理員功能有:年級(jí)管理、課程管理、試題管理、試卷管理、學(xué)生管理等。

運(yùn)行環(huán)境:jdk1.8、mysql5.x、eclipse、tomcat8.5\7.0、maven3.5\3.6。

Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)

Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)

Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)

Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)

Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)

Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)

統(tǒng)一管理學(xué)生 教師 管理員信息:

/**
 * 統(tǒng)一管理學(xué)生 教師 管理員信息
 */
@RestController
public class UserController {
 
    @Resource(name = "userService")
    private IUserService userService;
 
    /**
     * 查詢(xún)用戶信息
     * 先判斷用戶類(lèi)型 在查詢(xún)用戶信息
     */
    @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;
 
    /**
     * 管理員 查詢(xún)管理員列表
     */
    @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;
 
    /**
     * 教師 查詢(xún)考試列表
     */
    @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);
    }
 
    /**
     * 教師 新建狀態(tài)的考試信息可以刪除
     */
    @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);
    }
 
    /**
     * 教師 發(fā)布考試信息
     */
    @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"));
    }
 
    /**
     * 學(xué)生 查詢(xún)考試試題分組列表
     */
    @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"));
    }
 
    /**
     * 學(xué)生 查詢(xún)考試試題列表
     */
    @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"));
    }
 
    /**
     * 教師 判卷查詢(xún)?cè)囶}列表
     */
    @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"));
    }
 
    /**
     * 教師 記錄學(xué)生考試分?jǐn)?shù) 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);
    }
 
    /**
     * 教師 完成評(píng)分
     */
    @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;
 
    /**
     * 用戶登錄調(diào)用 在登陸成功生成兩個(gè)token 同時(shí)返回各自首頁(yè)
     * * 學(xué)生 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 續(xù)約
     */
    @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);
    }
 
    /**
     * 退出系統(tǒng)
     */
    @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<>();
    }
}

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Java如何實(shí)現(xiàn)在線高中考試系統(tǒng)”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI