Java Online Exam在线考试系统的实现
程序员文章站
2022-03-15 19:33:19
一、项目简述本系统主要实现的功能有: 学生以及老师的注册登录,在线考试,错题查询,学生管理,问题管理,错题管理,错题查询,分数查询,试卷管 理,人工组卷。自动组卷,教师,班级,统计等等管理功能。二、项...
一、项目简述
本系统主要实现的功能有: 学生以及老师的注册登录,在线考试,错题查询,学生管理,问题管理,错题管理,错题查询,分数查询,试卷管 理,人工组卷。自动组卷,教师,班级,统计等等管理功能。
二、项目运行
环境配置: jdk1.8 + tomcat8.5 + mysql + eclispe (intellij idea,eclispe,myeclispe,sts 都支持)
项目技术: vue+springboot+ springmvc + mybatis + thymeleaf + javascript + jquery + ajax + maven等等
课程信息控制器:
/** * yy */ @restcontroller @requestmapping(value = "/v1/subjects") public class subjectcontroller { private static logger logger = loggerfactory.getlogger(subjectcontroller.class); @autowired subjectservice subjectservice; @apioperation(value = "获取科目列表", notes = "") @requestmapping(value = "", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public pageinfo<subject> getsubjectlist(@requestparam(required = false) integer pageindex, @requestparam(required = false) integer pagesize, @requestparam(required = false) integer limit, @requestparam(required = false) integer offset) { if(pageindex != null && pagesize != null) { pagehelper.startpage(pageindex, pagesize); } list<subject> subjects = subjectservice.getsubjectlist(); pageinfo pageinfo = new pageinfo(subjects); return pageinfo; } @apioperation(value = "根据名字获取科目信息", notes = "根据科目名称获取科目详细信息") @apiimplicitparam(name = "name", value = "科目名称", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/{name}/name", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public list<subject> getsubjectbyname(@pathvariable string name) { return subjectservice.getsubjectfuzzy(name); } @apioperation(value = "获取课程信息", notes = "根据课程id获取课程详细信息") @apiimplicitparam(name = "idorname", value = "课程id或名称", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/search/{idorname}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public list<subject> getsubjectforsearch(@pathvariable string idorname) { list<subject> subjects = new arraylist<subject>(); subject subject = subjectservice.getsubjectbyname(idorname); if (subject == null) { try { subject = subjectservice.getsubjectbyid(idorname); } catch (exception e) { } } if (subject != null) { subjects.add(subject); } return subjects; } @apioperation(value = "创建课程", notes = "创建课程") @apiimplicitparam(name = "subject", value = "课程实体subject", required = true, datatype = "subject") @requestmapping(value = "", method = requestmethod.post) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public responseentity<?> postsubject(@requestbody subject subject) { if(subjectservice.getsubjectbyname(subject.getname()) != null) { return new responseentity<object>(new dto("课程已存在!"), httpstatus.internal_server_error); } subjectservice.savesubject(subject); return new responseentity(httpstatus.created); } @apioperation(value = "获取课程信息", notes = "根据课程id获取课程详细信息") @apiimplicitparam(name = "id", value = "课程id", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/{id}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public subject getsubject(@pathvariable string id) { return subjectservice.getsubjectbyid(id); } @apioperation(value = "更新课程信息", notes = "根据课程id更新用户信息") @apiimplicitparam(name = "subject", value = "课程实体", required = true, datatype = "subject") @requestmapping(value = "", method = requestmethod.put) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public responseentity<?> putsubject(@requestbody subject subject) { subjectservice.updatesubject(subject); return new responseentity(httpstatus.ok); } @apioperation(value = "删除课程", notes = "根据课程id删除课程") @apiimplicitparam(name = "id", value = "课程id", required = true, datatype = "long", paramtype = "path") @requestmapping(value = "/{id}", method = requestmethod.delete) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public responseentity<?> deletesubject(@pathvariable string id) { try { subjectservice.deletesubject(id); }catch (runtimeexception e) { return new responseentity(new dto("该课程包含有考试,不能删除"), httpstatus.internal_server_error); } return new responseentity(httpstatus.ok); } }
题目信息控制器:
/** * yy */ @restcontroller @requestmapping(value = "/v1/questions") public class questioncontroller { private static logger logger = loggerfactory.getlogger(questioncontroller.class); @autowired questionservice questionservice; @autowired paperanswerpaperservice paperanswerpaperservice; @apioperation(value = "获取题目分页列表", notes = "") @requestmapping(value = "", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public pageinfo<question> getquestionlistbypage(@requestparam(required = false) integer pageindex, @requestparam(required = false) integer pagesize, @requestparam(required = false) integer limit, @requestparam(required = false) integer offset) { if(pageindex != null && pagesize != null) { pagehelper.startpage(pageindex, pagesize); } list<question> questions = questionservice.getquestionlist(); pageinfo pageinfo = new pageinfo(questions); return pageinfo; } @apioperation(value = "获取试卷题目分页列表", notes = "") @requestmapping(value = "/papers/{paperid}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public pageinfo<question> getquestionlistbypaper(@pathvariable string paperid, @requestparam(required = false) integer pageindex, @requestparam(required = false) integer pagesize, @requestparam(required = false) integer limit, @requestparam(required = false) integer offset) { if(pageindex != null && pagesize != null) { pagehelper.startpage(pageindex, pagesize); } list<question> questions = questionservice.getquestionlistbypaper(paperid); pageinfo pageinfo = new pageinfo(questions); return pageinfo; } @apioperation(value = "获取试卷题目数量", notes = "") @requestmapping(value = "/papers/{paperid}/count", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public responseentity<?> getquestioncountbypaper(@pathvariable string paperid) { integer count = questionservice.countbypaperid(paperid); return new responseentity<object>(count, httpstatus.ok); } @apioperation(value = "创建题目", notes = "创建题目") @apiimplicitparams({ @apiimplicitparam(name = "question", value = "题目实体question", required = true, datatype = "question"), @apiimplicitparam(name = "id", value = "试卷id", required = true, datatype = "string", paramtype = "path") }) @requestmapping(value = "/{id}", method = requestmethod.post) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public responseentity<?> postquestion(@pathvariable("id") string id, @requestbody question question) { questionservice.savequestion(id, question); return new responseentity(httpstatus.created); } @apioperation(value = "获取题目信息", notes = "根据题目id获取题目详细信息") @apiimplicitparam(name = "id", value = "题目id", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/{id}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public question getquestion(@pathvariable string id) { return questionservice.getquestion(id); } @apioperation(value = "根据试卷id和题目编号获取题目信息", notes = "根据题目id获取题目详细信息") @apiimplicitparams({ @apiimplicitparam(name = "paperid", value = "试卷id", required = true, datatype = "string", paramtype = "path"), @apiimplicitparam(name = "number", value = "题目编号", required = true, datatype = "string", paramtype = "path") }) @requestmapping(value = "/papers/{paperid}/questions/{number}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public question getquestionbypaperidandquestionid(@pathvariable string paperid, @pathvariable integer number, @requestparam(required = false) string answerpaperid) { paperanswerpaper paperanswerpaper = null; //传入的是答卷id if(answerpaperid != null) { // todo: 2017-04-17 paperanswerpaper = paperanswerpaperservice.getbyanswerpaperid(answerpaperid); if(paperanswerpaper != null) { return questionservice.getquestionbypaperidandquestionnumber(paperanswerpaper.getpaperid(), number); }else { logger.error("根据答卷id获取答卷失败"); } } return questionservice.getquestionbypaperidandquestionnumber(paperid, number); } @apioperation(value = "获取题目信息", notes = "根据题目name获取题目详细信息") @apiimplicitparam(name = "name", value = "试卷name", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/name/{name}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public list<question> getquestionbyname(@pathvariable string name) { //模糊查询 return questionservice.getquestionfuzzy(name); } @apioperation(value = "获取题目信息", notes = "根据试卷id获取所有题目") @apiimplicitparam(name = "paperid", value = "试卷id", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/papers/{paperid}/questions", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public list<question> getquestionbypaperid(@pathvariable string paperid) { return questionservice.getquestionbypaperid(paperid); } @apioperation(value = "获取题目信息", notes = "根据试卷id获取所有题目,但不返回答案") @apiimplicitparam(name = "paperid", value = "试卷id", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/papers/{paperid}/ignore", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public list<question> getquestionbypaperidignoreanswer(@pathvariable string paperid) { return questionservice.getquestionbypaperidignoreanswer(paperid); } @apioperation(value = "更新题目信息", notes = "根据题目id更新题目信息") @apiimplicitparam(name = "question", value = "题目实体", required = true, datatype = "question") @requestmapping(value = "", method = requestmethod.put) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public responseentity<?> putquestion(@requestbody question question) { questionservice.updatequestion(question); return new responseentity(httpstatus.ok); } @apioperation(value = "删除题目", notes = "根据题目id删除试卷") @apiimplicitparam(name = "id", value = "题目id", required = true, datatype = "string", paramtype = "path") @requestmapping(value = "/{id}", method = requestmethod.delete) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public responseentity<?> deletequestion(@pathvariable string id) { questionservice.deletequestion(id); return new responseentity(httpstatus.ok); } }
考试控制层,负责试卷提交等:
/** * 考试控制层,负责试卷提交等 */ @restcontroller @requestmapping("/v1/exam") public class examcontroller { @autowired examservice examservice; @autowired answerpaperservice answerpaperservice; @autowired answerquestionservice answerquestionservice; @autowired answerpaperquestionservice answerpaperquestionservice; @autowired questionservice questionservice; @autowired paperservice paperservice; @autowired wrongquestionservice wrongquestionservice; @autowired paperanswerpaperservice paperanswerpaperservice; @apioperation(value = "根据试卷id和题目编号获取题目信息", notes = "根据题目id获取题目详细信息") @apiimplicitparams({ @apiimplicitparam(name = "paperid", value = "试卷id", required = true, datatype = "string", paramtype = "path"), @apiimplicitparam(name = "number", value = "题目编号", required = true, datatype = "string", paramtype = "path") }) @requestmapping(value = "/questions/{number}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public question getquestionbypaperidandquestionid(@requestparam string paperid, @requestparam string username, @requestparam(required = false) string answerpaperid, @pathvariable integer number) { question question = null; answerquestion answerquestion = null; if(answerpaperid == null) { paper paper = paperservice.getpaperbyid(paperid); if(paper != null) { answerpaper answerpaper = answerpaperservice.findbyansweruserandpapername(username, paper.getname()); if(answerpaper != null) { answerquestion = answerquestionservice.getanswerquestionbypaperidandquestionnumber(answerpaper.getid(), number); } } }else { answerquestion = answerquestionservice.getanswerquestionbypaperidandquestionnumber(answerpaperid, number); } if(answerquestion == null) { question = questionservice.getquestionbypaperidandquestionnumber(paperid, number); if(question != null) { //答案不返回 question.setanswer(""); } } else { question = new question(); question.setid(answerquestion.getid()); question.setnumber(answerquestion.getnumber()); question.settitle(answerquestion.gettitle()); question.setscore(answerquestion.getscore()); question.settype(answerquestion.gettype()); question.setoptiona(answerquestion.getoptiona()); question.setoptionb(answerquestion.getoptionb()); question.setoptionc(answerquestion.getoptionc()); question.setoptiond(answerquestion.getoptiond()); question.setanswer(answerquestion.getanswer()); } return question; } @requestmapping(value = "/submit/{type}/{username}", method = requestmethod.post) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public responseentity<?> submit(@requestbody paper paper, @pathvariable string type, @pathvariable string username, @requestparam(required = false) string answerpaperid) { /** * 更改试卷状态,finished:true */ if(type.equals("official")) { /** * 正式考试 */ answerpaper answerpaper = new answerpaper(); if(answerpaperid != null) { answerpaper.setid(answerpaperid); }else { return new responseentity<object>(httpstatus.internal_server_error); } answerpaper.setanswertime(new simpledateformat("yyyy-mm-dd hh:mm:ss").format(new date())); answerpaper.setpapername(paper.getname()); answerpaper.setansweruser(username); answerpaper.setchecked("false"); answerpaper.setfinished("true"); answerpaper.settype("official"); examservice.updateanswerpaper(answerpaper); } else if(type.equals("simulate")) { /** * 模拟考试 */ answerpaper answerpaper = new answerpaper(); if(answerpaperid != null) { answerpaper.setid(answerpaperid); }else { return new responseentity<object>(httpstatus.internal_server_error); } answerpaper.setanswertime(new simpledateformat("yyyy-mm-dd hh:mm:ss").format(new date())); answerpaper.setpapername(paper.getname()); answerpaper.setansweruser(username); answerpaper.setchecked("false"); answerpaper.setfinished("true"); answerpaper.settype("simulate"); examservice.updateanswerpaper(answerpaper); }else if(type.equals("practice")) { /** * 1.接收提交的试卷 * 2.计算成绩 * 3.记录考试记录 * 4.返回计算结果 */ int score = 0; //正确题目数 double right = 0.0; //错误题目数 double wrong = 0.0; double correctrate = 0.0; list<question> questions = questionservice.getquestionbypaperid(paper.getid()); answerpaper answerpaper = answerpaperservice.findbyansweruserandpapername(username, paper.getname()); list<answerquestion> answerquestions = answerquestionservice.findbyanswerpaperid(answerpaper.getid()); /*保存题目信息,返回给前端*/ list<dtorightandwrong> results = new arraylist<dtorightandwrong>(); dtorightandwrong dtorightandwrong = null; //遍历提交的试卷的题目 for(answerquestion answerquestion : answerquestions) { //遍历包含正确答案的题目 for(question question : questions) { /** * 1.题目序号相同 * 2.结果与答案相同 */ if(answerquestion.getnumber().equals(question.getnumber())) { if(answerquestion.getanswer().equals(question.getanswer())) { /*累计得分*/ score += integer.parseint(question.getscore()); right ++; }else { wrong ++; //记录错题 dtorightandwrong = new dtorightandwrong(); dtorightandwrong.setquestion(question); dtorightandwrong.setanswerquestion(answerquestion); results.add(dtorightandwrong); //保存错题 wrongquestion wrongquestion = new wrongquestion(); try{ beanutils.copyproperties(wrongquestion, answerquestion); wrongquestion.setusername(username); wrongquestion.setrightanswer(question.getanswer()); wrongquestion.setanalysis(question.getanalysis()); if(wrongquestionservice.getwrongquestion(wrongquestion.getid()) == null) { wrongquestionservice.savequestion(wrongquestion); } }catch (exception e) { system.out.println(wrongquestion.tostring()); } } } } } //计算正确率 correctrate = (right/(right + wrong)) * 100; dtoresult result = new dtoresult(); result.setscore(score); result.setright(right); result.setwrong(wrong); result.setcorrectrate(correctrate); result.setresults(results); paper paper1 = paperservice.getpaperbyid(paper.getid()); //更新参与人数 paper1.setpeoples(string.valueof(integer.parseint(paper1.getpeoples()) + 1)); paperservice.updatepaper(paper1); return new responseentity<object>(result, httpstatus.ok); } paper paper1 = paperservice.getpaperbyid(paper.getid()); //更新参与人数 paper1.setpeoples(string.valueof(integer.parseint(paper1.getpeoples() + 1))); paperservice.updatepaper(paper1); return new responseentity<object>(httpstatus.ok); } /** * 提交题目 * @param username * @param dtoanswerpaper * @return */ @requestmapping(value = "/submit/one/{username}", method = requestmethod.post) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public responseentity<?> submitone(@pathvariable string username, @requestbody dtoanswerpaper dtoanswerpaper) { paper paper = dtoanswerpaper.getpaper(); question question = dtoanswerpaper.getquestion(); //判断数据库是否保存了这次答卷 answerpaper answerpaper = answerpaperservice.getanswerpaperbynameanduser(paper.getname(), username); answerquestion answerquestion = null; answerpaperquestion answerpaperquestion = null; list<answerquestion> answerquestions = null; //重新生成id string answerpaperid = idgen.uuid(); string answerquestionid = idgen.uuid(); //答卷为空,则执行保存 if(answerpaper == null) { answerpaper = new answerpaper(); answerpaper.setid(answerpaperid); answerpaper.setanswertime(new simpledateformat("yyyy-mm-dd hh:mm:ss").format(new date())); answerpaper.setpapername(paper.getname()); answerpaper.settype(paper.gettype()); answerpaper.setansweruser(username); answerpaper.setchecked("false"); answerpaper.setfinished("false"); //保存答卷 answerpaperservice.saveanswerpaper(answerpaper); // todo: 2017-04-17 保存试卷答卷 paperanswerpaper paperanswerpaper = new paperanswerpaper(); paperanswerpaper.setpaperid(paper.getid()); paperanswerpaper.setanswerpaperid(answerpaperid); paperanswerpaperservice.save(paperanswerpaper); //新记录 answerquestion = new answerquestion(); //初始化信息 answerquestion.setid(answerquestionid); answerquestion.settitle(question.gettitle()); answerquestion.settype(question.gettype()); answerquestion.setnumber(question.getnumber()); answerquestion.setoptiona(question.getoptiona()); answerquestion.setoptionb(question.getoptionb()); answerquestion.setoptionc(question.getoptionc()); answerquestion.setoptiond(question.getoptiond()); answerquestion.setcontent(question.getcontent()); answerquestion.setscore(question.getscore()); answerquestion.setanalysis(question.getanalysis()); answerquestion.setanswer(question.getanswer()); answerpaperquestion = new answerpaperquestion(); answerpaperquestion.setanswerpaperid(answerpaper.getid()); answerpaperquestion.setanswerquestionid(answerquestionid); //保存 answerquestionservice.saveanswerquestion(answerquestion); answerpaperquestionservice.saveanswerpaperquestion(answerpaperquestion); return new responseentity<object>(answerpaper, httpstatus.ok); } else { answerquestions = answerquestionservice.findbyanswerpaperid(answerpaper.getid()); if(answerquestions != null && answerquestions.size() > 0) { int count = 0; answerquestion existanswerquestion = null; for(answerquestion question1 : answerquestions) { if (question1.getnumber().equals(question.getnumber())) { count++; existanswerquestion = question1;//保存当前存在的记录 } } //记录不存在 if(count == 0) { //新记录 answerquestion = new answerquestion(); answerpaperquestion = new answerpaperquestion(); answerquestion = new answerquestion(); //初始化信息 answerquestion.setid(answerquestionid); answerquestion.settitle(question.gettitle()); answerquestion.settype(question.gettype()); answerquestion.setnumber(question.getnumber()); answerquestion.setoptiona(question.getoptiona()); answerquestion.setoptionb(question.getoptionb()); answerquestion.setoptionc(question.getoptionc()); answerquestion.setoptiond(question.getoptiond()); answerquestion.setcontent(question.getcontent()); answerquestion.setscore(question.getscore()); answerquestion.setanalysis(question.getanalysis()); answerquestion.setanswer(question.getanswer()); answerpaperquestion = new answerpaperquestion(); answerpaperquestion.setanswerpaperid(answerpaper.getid()); answerpaperquestion.setanswerquestionid(answerquestionid); //保存 answerquestionservice.saveanswerquestion(answerquestion); answerpaperquestionservice.saveanswerpaperquestion(answerpaperquestion); } else { //记录存在,则执行更新 // todo: 2017/3/30 //更新当前存在的记录 existanswerquestion.setanswer(question.getanswer()); answerquestionservice.updateanswerquestion(existanswerquestion); } } } return new responseentity<object>(answerpaper, httpstatus.ok); } }
答卷控制层,用于获取已经提交的答卷:
/** * 答卷控制层,用于获取已经提交的答卷 */ @restcontroller @requestmapping("/v1/answer-papers") public class answerpapercontroller { @autowired answerpaperservice answerpaperservice; @autowired answerquestionservice answerquestionservice; /** * 根据id查找 * @param id * @return */ @requestmapping(value = "/{id}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public answerpaper getanswerpaper(@pathvariable string id) { return answerpaperservice.getanswerpaperbyid(id); } /** * 根据name查找 * @param name * @return */ @requestmapping(value = "/name/{name}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public list<answerpaper> getanswerpaperbyname(@pathvariable string name) { return answerpaperservice.getanswerpaperfuzzy(name); } /** * 根据答卷id和题目编号获取题目信息 * @param paperid * @param number * @return */ @requestmapping(value = "/papers/{paperid}/questions/{number}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public answerquestion getquestionbypaperidandquestionid(@pathvariable string paperid, @pathvariable integer number) { answerquestion answerquestion = answerquestionservice.getanswerquestionbypaperidandquestionnumber(paperid, number); return answerquestion; } /** * 已分页方式获取数据 * @param username * @param pageindex * @param pagesize * @param limit * @param offset * @return */ @requestmapping(value = "/users/{username}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public pageinfo<answerpaper> getlistbyuser(@pathvariable("username") string username, @requestparam(required = false) integer pageindex, @requestparam(required = false) integer pagesize, @requestparam(required = false) integer limit, @requestparam(required = false) integer offset) { if(pageindex != null && pagesize != null) { pagehelper.startpage(pageindex, pagesize); } list<answerpaper> answerpapers = answerpaperservice.getanswerpaperlistbyansweruser(username); pageinfo pageinfo = new pageinfo(answerpapers); return pageinfo; } @requestmapping(value = "/users/{username}/type/{type}", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public pageinfo<answerpaper> getlistbyuserandtype(@pathvariable("username") string username, @pathvariable("type") string type, @requestparam(required = false) integer pageindex, @requestparam(required = false) integer pagesize, @requestparam(required = false) integer limit, @requestparam(required = false) integer offset) { if(pageindex != null && pagesize != null) { pagehelper.startpage(pageindex, pagesize); } list<answerpaper> answerpapers = answerpaperservice.getanswerpaperlistbyansweruserandtype(username, type); pageinfo pageinfo = new pageinfo(answerpapers); return pageinfo; } /** * 获取未批改或已批改的答卷数量, * @return */ @requestmapping("/check") @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public dtotask countuncheckanswerpaper() { dtotask dtotask = new dtotask(); integer checked = answerpaperservice.countcheck("true"); integer unchecked = answerpaperservice.countcheck("false"); dtotask.setchecked(checked); dtotask.setunchecked(unchecked); return dtotask; } /** * 以分页方式获取数据 * @param pageindex * @param pagesize * @param limit * @param offset * @return */ @requestmapping(value = "", method = requestmethod.get) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public pageinfo<answerpaper> getlistbyuser(@requestparam(required = false) integer pageindex, @requestparam(required = false) integer pagesize, @requestparam(required = false) integer limit, @requestparam(required = false) integer offset) { if(pageindex != null && pagesize != null) { pagehelper.startpage(pageindex, pagesize); } list<answerpaper> answerpapers = answerpaperservice.getanswerpaperlist(); pageinfo pageinfo = new pageinfo(answerpapers); return pageinfo; } /** * 更新 * @param answerpaper * @return */ @requestmapping(value = "", method = requestmethod.put) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public responseentity<?> putpaper(@requestbody answerpaper answerpaper) { answerpaperservice.updatepaper(answerpaper); return new responseentity(httpstatus.ok); } /** * 计算考试成绩 * @param id * @return */ @requestmapping(value = "/{id}/calculate", method = requestmethod.put) @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "') or hasauthority('" + role.role_student + "')") public responseentity<?> calculationscore(@pathvariable string id) { /** * 计算成绩 */ list<answerquestion> questions = answerquestionservice.findbyanswerpaperid(id); if(questions != null && questions.size() > 0) { int score = 0; try { for(answerquestion question : questions) { score += integer.parseint(question.getmarkscore()); } } catch (exception e) { // todo: 2017/4/1 } /** * 保存成绩 */ answerpaper answerpaper = new answerpaper(); answerpaper.setid(id); answerpaper.setscore(integer.tostring(score)); answerpaper.setchecked("true"); answerpaperservice.updatepaper(answerpaper); } else { // todo: 2017/4/1 } return new responseentity<object>(httpstatus.ok); } @requestmapping(value = "/analysis/paper") @preauthorize("hasauthority('" + role.role_teacher + "') or hasauthority('" + role.role_admin + "')") public list<paperanalysis> analysispaper() { return answerpaperservice.analysispaper(); } }
以上就是java online exam在线考试系统的实现的详细内容,更多关于java 在线考试系统的资料请关注其它相关文章!