在本考试系统中,管理员、老师、学生三个角色是相当于是三个系统。
在线考试系统管理员登录页面
学科管理页面(可以对科目进行增删改查)
/**
* 分页查询科目,展示给页面
* @param curr
* @param model
* @return
*/
@RequestMapping("/list")
public String showSubject(Integer curr, Model model){
if (curr == null){
curr = 1;
}
PageInfo<Subject> pageInfo = subjectService.showList(curr, 5);
model.addAttribute("pageInfo", pageInfo);
return "/subject/list";
}
/**
* 跳转到添加科目页面
* @return
*/
@RequestMapping(value = "/add", method=RequestMethod.GET)
public String addSubjectView(){
return "/subject/add";
}
/**
* 添加科目
* @param subject
* @return
*/
@RequestMapping(value = "/add", method=RequestMethod.POST)
public @ResponseBody AjaxResult addSubject(Subject subject){
//判断学科名称是否为空
if (CommonUtils.isEmpty(subject.getName())){
return AjaxResult.errorInstance("学科名称不能为空");
}
//判断学科名称是否存在
if (subjectService.isExisted(subject)){
return AjaxResult.errorInstance("学科名称不能重复");
}
//添加科目
subjectService.insert(subject);
return AjaxResult.successInstance("添加成功");
}
/*
* 跳转到修改页面
*/
@RequestMapping(value = "/update", method=RequestMethod.GET)
public String updateSubjectView(int id, Model model){
Subject subject = subjectService.selectOne(id);
model.addAttribute("subject", subject);
return "/subject/update";
}
/**
* 修改科目
* @param subject
* @return
*/
@RequestMapping(value = "/update", method=RequestMethod.POST)
public @ResponseBody AjaxResult updateSubject(Subject subject){
//判断学科名称是否为空
if (CommonUtils.isEmpty(subject.getName())){
return AjaxResult.errorInstance("学科名称不能为空");
}
//判断学科名称是否存在
if (subjectService.isExisted(subject)){
return AjaxResult.errorInstance("学科名称不能重复");
}
subjectService.update(subject);
return AjaxResult.successInstance("修改成功");
}
@RequestMapping(value = "/delete")
public @ResponseBody AjaxResult deleteSubject(int id){
if (!chapterService.isEmpty(id)){
return AjaxResult.errorInstance("对不起,该课程中的篇章没有删除完,不能删除!");
}
subjectService.delete(id);
return AjaxResult.successInstance("删除成功");
}
章节管理(一个科目有多个章节)
**学生信息管理页面 **
**老师信息管理页面 **
老师科目管理页面 (老师所教的科目)
**班级管理页面 **
班级学生管理 (每个班级都有学生)
班级科目管理 (每个班级都有所要学习的科目,和所对应的老师)
**考试管理页面 **
发布考试页面 (根据考试科目,试题模块类型,试题数量在系统中随机组卷,试题分值为每个小题的分值)
//发布考试时试题模块,试题数量,分值对应的JavaBean对象
public class TextModel {
private Integer textModelId;
private Integer textCount;
private Integer grade;
public Integer getTextModelId() {
return textModelId;
}
public void setTextModelId(Integer textModelId) {
this.textModelId = textModelId;
}
public Integer getTextCount() {
return textCount;
}
public void setTextCount(Integer textCount) {
this.textCount = textCount;
}
public Integer getGrade() {
return grade;
}
public void setGrade(Integer grade) {
this.grade = grade;
}
}
//模块集合类
public class BeanTextModel {
private List<TextModel> listTextModel = new ArrayList<TextModel>();
public List<TextModel> getListTextModel() {
return listTextModel;
}
public void setListTextModel(List<TextModel> listTextModel) {
this.listTextModel = listTextModel;
}
}
/**
* 初始化时间类型
* @param binder
*/
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
/**
* 显示考试信息列表
* @param curr
* @param model
* @return
*/
@RequestMapping("/list")
public String showExam(Integer curr, Model model){
if (curr == null){
curr = 1;
}
//查询出发布的开始信息列表
PageInfo<Publishexam> publishexamList = publishExamService.selectAll(curr, 5);
model.addAttribute("publishexamList", publishexamList);
return "/exam/list";
}
/**
* 跳转到考试页面
* @param model
* @return
*/
@RequestMapping(value="/add", method=RequestMethod.GET)
public String addExamView(Model model){
//查询试题和试题模块列表,在前端页面上显示
List<Subject> textList = subjectService.showList();
List<Textmodel> textModelList = textModelService.showList();
model.addAttribute("textList", textList);
model.addAttribute("textModelList", textModelList);
return "/exam/add";
}
/**
* 添加考试信息
* @param request
* @param publishExam
* @param textModelIds
* @param beanTextModel
* @return
*/
@RequestMapping(value="/add", method=RequestMethod.POST)
@ResponseBody
public AjaxResult addExam(HttpServletRequest request,PublishexamWithBLOBs publishExam,int[] textModelIds, BeanTextModel beanTextModel){
//添加考试信息,获取到是哪个管理员添加的考试信息
HttpSession session = request.getSession();
Admin admin = (Admin) session.getAttribute("adminInfo");
publishExam.setAdminId(admin.getId());
publishExam.setAdminName(admin.getName());
publishExam.setStatus(0);
publishExam.setPublishtime(new Date());
//查询出考试的科目
Subject subject = subjectService.selectOne(publishExam.getSubjectId());
publishExam.setSubjectName(subject.getName());
//因为试题模块数量,题目数量,题目分值是一直变化的
//存储在数据库中比较字段不好建立,因此我们将这块提取出一个TextModel类
//将多个模块添加到List集合中转成JSON格式存储到数据库中
List<TextModel> list = new ArrayList<TextModel>();
if (textModelIds != null){
for (int i : textModelIds) {
for(TextModel textModel : beanTextModel.getListTextModel()){
if (textModel.getTextModelId() != null && i == textModel.getTextModelId()){
list.add(textModel);
}
}
}
String json = JsonUtils.toJson(list);
publishExam.setExam(json);
}
publishExamService.insert(publishExam);
return AjaxResult.successInstance("添加成功");
}
/**
* 跳转到发布考试页面
* @param id
* @param model
* @return
*/
@SuppressWarnings("unchecked")
@RequestMapping(value="/update", method=RequestMethod.GET)
public String updateExamView(int id, Model model){
PublishexamWithBLOBs publishExam = publishExamService.selectByKey(id);
//将存储的JSON取出并解析成Java对象
ArrayList<TextModel> updateList = JsonUtils.toBean(publishExam.getExam(), ArrayList.class, TextModel.class);
//获取科目列表
List<Subject> textList = subjectService.showList();
//获取试题模块列表
List<Textmodel> textModelList = textModelService.showList();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = dateFormat.format(publishExam.getExamtime());
model.addAttribute("date", date);
model.addAttribute("textList", textList);
model.addAttribute("textModelList", textModelList);
model.addAttribute("updateList", updateList);
model.addAttribute("publishExam", publishExam);
return "/exam/update";
}
/**
* 修改所发布的考试
* @param request
* @param id
* @param publishExam
* @param textModelIds
* @param beanTextModel
* @return
*/
@RequestMapping(value="/update", method=RequestMethod.POST)
@ResponseBody
public AjaxResult updateExam(HttpServletRequest request,int id, PublishexamWithBLOBs publishExam,int[] textModelIds, BeanTextModel beanTextModel){
HttpSession session = request.getSession();
Admin admin = (Admin) session.getAttribute("adminInfo");
publishExam.setAdminId(admin.getId());
publishExam.setAdminName(admin.getName());
publishExam.setStatus(0);
publishExam.setPublishtime(new Date());
Subject subject = subjectService.selectOne(publishExam.getSubjectId());
publishExam.setSubjectName(subject.getName());
List<TextModel> list = new ArrayList<TextModel>();
if (textModelIds != null){
for (int i : textModelIds) {
for(TextModel textModel : beanTextModel.getListTextModel()){
if (textModel.getTextModelId() != null && i == textModel.getTextModelId()){
list.add(textModel);
}
}
}
String json = JsonUtils.toJson(list);
publishExam.setExam(json);
}
publishExamService.update(publishExam);
return AjaxResult.successInstance("修改成功");
}
/**
* 删除考试信息
* @param id
* @return
*/
@RequestMapping(value = "/delete")
public @ResponseBody AjaxResult deleteExam(int id){
publishExamService.delete(id);
return AjaxResult.successInstance("删除成功");
}
**发布考试修改页面 **
** 查询学生成绩 **
老师管理 (可以删除老师信息,重置老师密码)
** 学生管理 (可以删除学生信息,重置学生密码) **
因为基本上都是增删改查方法,差不多,粘贴所有代码没有必要。(发布考试和修改考试信息是管理员中的难点,因此我粘出了代码)
TextModel是发布试题时为了存储JSON抽取的JavaBean类
Textmodel是试题模块类
(当时创建类的时候没有注意命名)