基于Java实现考试管理系统

项目简述

本系统功能包括:

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

项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。

项目技术

Springboot + Maven + Jpa+ Vue 等等组成,B/S模式 + Maven管理等等。

效果图展示

基于Java实现考试管理系统_第1张图片

基于Java实现考试管理系统_第2张图片

基于Java实现考试管理系统_第3张图片

基于Java实现考试管理系统_第4张图片

基于Java实现考试管理系统_第5张图片

主要代码

登录控制层:

@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 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 check() {
        return new Result<>();
    }
 
    /**
     * token 续约
     */
    @RequestMapping(value = "/login/refresh", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result 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 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 qryUserInfo() {
        return userService.qryUserInfo();
    }
 
    /**
     * 更新用户信息
     */
    @RequestMapping(value = "/user/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public Result 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 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 qryPage(HttpRequest request) {
        Map 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 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 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 del(HttpRequest request) {
        List 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考试管理系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(基于Java实现考试管理系统)