基于SSM框架的在线考试系统分为学生和教师两种角色。 学生可以注册、登录,进入系统后如果有教师安排的考试,可以进行考试和查看已经结束的考试结果。
教师拥有基本信息管理、班级管理、教师管理、学生管理、考试管理、试题管理、考试安排管理和查看以往考试结果等功能,对整个系统拥有最高管理权限。
public class GradeInfoHandler {
@Autowired
@Qualifier("gson")
private Gson gson;
@Autowired
private GradeInfoService gradeInfoService;
private Logger logger = Logger.getLogger(GradeInfoHandler.class);
/**
* 获取所有年级集合
* @return
*/
@RequestMapping(value="/grades")
public ModelAndView getGrades() {
logger.info("获取所有年级");
ModelAndView model = new ModelAndView();
model.setViewName("admin/grades");
//获取所有年级
List<GradeInfo> grades = gradeInfoService.getGrades();
model.addObject("grades", grades);
return model;
}
/**
* 预添加年级处理
* @param map
* @return
*/
@RequestMapping("/preAddGrade")
public String preAddGrade(Map<String, Object> map) {
logger.info("年级添加预处理");
map.put("grade", new GradeInfo());
return "admin/gradeedit";
}
/**
* 添加年级
* @param grade
* @param request
* @return
*/
@RequestMapping(value="/grade", method=RequestMethod.POST)
public String isAddGrade(GradeInfo grade, HttpServletRequest request) {
logger.info("添加年级 "+grade);
if (grade == null) {
logger.error("年级 "+grade+" 为空");
request.setAttribute("error", "年级添加失败,请稍后再试!");
return "error";
}
int row = gradeInfoService.isAddGrade(grade);
if (row < 1) {
logger.error("年级添加失败");
request.setAttribute("error", "年级添加失败,请稍后再试!");
return "error";
}
return "redirect:grades";
}
/**
* 预修改年级处理
* @param gradeId 待修改年级编号
* @param map
* @return
*/
@RequestMapping(value="/grade/update/{gradeId}", method=RequestMethod.GET)
public String preUpdateGrade(@PathVariable("gradeId") Integer gradeId,
Map<String, Object> map) {
logger.info("年级修改预处理");
map.put("grade", gradeInfoService.getGradeById(gradeId));
return "/admin/gradeedit";
}
/**
* 修改年级信息
* @param grade
* @param request
* @return
*/
@RequestMapping(value="/grade/update/grade", method=RequestMethod.PUT)
public String isUpdateGrade(GradeInfo grade, HttpServletRequest request) {
logger.info("修改年级 "+grade+" 的信息");
int row = gradeInfoService.isUpdateGrade(grade);
if (row < 1) {
logger.error("年级修改失败");
request.setAttribute("error", "年级修改失败,请稍后再试!");
return "/error";
}
return "redirect:/grades";
}
/**
* 删除年级
* @param gradeId
* @param request
* @return
*/
@RequestMapping(value="grade/del/{gradeId}", method=RequestMethod.DELETE)
public String isDelGrade(@PathVariable("gradeId") Integer gradeId, HttpServletRequest request) {
logger.info("删除年级 "+gradeId);
int row = gradeInfoService.isDelGrade(gradeId);
if (row < 1) {
logger.error("年级删除失败");
request.setAttribute("error", "年级删除失败,请稍后再试!");
return "/error";
}
return "redirect:/grades";
}
}
演示视频
|