欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于Java实现考试管理系统

程序员文章站 2022-03-06 13:57:54
目录项目简述项目运行项目技术效果图展示主要代码项目简述本系统功能包括:支持单选题、多选题、判断题支持学生(student)、教师(teacher)、管理员(admin)三种角色学生:参加考试和查看我的...

项目简述

本系统功能包括:

支持单选题、多选题、判断题支持学生(student)、教师(teacher)、管理员(admin)三种角色学生:参加考试和查看我的考试教师:学生的所有权限+创建/编辑题目+创建/编辑考试管理员:教师的所有权限+管理用户。

项目运行

环境配置:

jdk1.8 + tomcat8.5 + mysql + hbuilderx(webstorm也行)+ eclispe(intellij idea,eclispe,myeclispe,sts都支持)。

项目技术

springboot + maven + jpa+ vue 等等组成,b/s模式 + maven管理等等。

效果图展示

基于Java实现考试管理系统

基于Java实现考试管理系统

基于Java实现考试管理系统

基于Java实现考试管理系统

基于Java实现考试管理系统

主要代码

登录控制层:

@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实现考试管理系统的文章就介绍到这了,更多相关java考试管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!