基于B/S架构的课程在线学习与测试系统
启动说明
项目为maven管理,最近集成了redis,所以在运行项目是先要下载redis并启动客户端,方可正常运行项目,由于只需要下载redis,无需其他配置,这里就不做过多说明。
最近更新
集成redis来保存用户登录信息,添加过滤器重置用户登录有效期。拦截器实现统一登录和权限校验(相关重构还未完成)。
修改配置文件:com.bs.commonn.RedisPool 地址、端口号
pool = new JedisPool(config,“127.0.0.1”,6379,1000*2);
修改数据库配置文件,导入项目bs.sql文件
学生账号测试:lwj 123456
教师测试账号:lwj 123456
管理员测试账号:admin admin
项目采用前后端分离技术实现
-
框架:SSM(Spring,SpringMVC,Mybatis)
-
缓存:redis
-
数据库:MySQL
-
IDE:Intellij IDEA/Eclipse
-
其他:Maven,Git
项目亮点
-
前后端分离。
-
用户登录权限区分和控制。
-
防止横向越权和纵向越权。
-
密码MD5明文加密。
-
设计高复用的服务器响应对象。
-
guava缓存。
-
pojo,vo抽象模型。
-
数据绑定对象。
-
Mybatis分页
-
Bootstrap。
-
artTemplate,artDialog,iframe前端模板使用。
-
select2、toastr、sweetalert等等前端插件的使用。
-
redis缓存。
-
全局异常处理,拦截器权限统一检验。
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
* @param className
* 班级名称 可用于模糊查询
* @param classId
* 班级编号
* @return
*/
@RequestMapping(value = "/classes", method = RequestMethod.GET)
public ModelAndView getClasses(@RequestParam(value = "gradeId", required = false) Integer gradeId,
@RequestParam(value = "className", required = false) String className,
@RequestParam(value = "classId", required = false) Integer classId) {
ModelAndView model = new ModelAndView();
ClassInfo classInfo = new ClassInfo();
/* 处理查询条件 */
if (gradeId != null) {
GradeInfo gradeInfo = new GradeInfo();
gradeInfo.setGradeId(gradeId);
classInfo.setGrade(gradeInfo);
}
}
/**
* 教师查看自己的信息
*
* @param teacherId
* @return
*/
@RequestMapping("/selfinfo/{teacherId}")
public ModelAndView loginTeacherSelf(@PathVariable("teacherId") Integer teacherId) {
ModelAndView model = new ModelAndView();
logger.error("教师 " + teacherId + " 查看自己的信息");
if (teacherId == null) {
model.setViewName("../error");
return model;
} else {
List<TeacherInfo> teachers = new ArrayList<TeacherInfo>();
TeacherInfo teacher = teacherInfoService.getTeacherById(teacherId);
teachers.add(teacher);
model.addObject("teachers", teachers);
model.setViewName("/admin/teacher/teachers");
return model;
}
}
/**
* 教师退出登录
*
if (studentTotal % pageShow == 0)
pageTotal = studentTotal / pageShow;
else
pageTotal = studentTotal / pageShow + 1;
model.addObject("pageTotal", pageTotal);
model.addObject("pageNow", startPage);
return model;
}
/**
* 根据编号获取学生信息
* @param studentId
* @return
*/
@RequestMapping("/student/{studentId}")
public ModelAndView getCourseById(@PathVariable("studentId") Integer studentId) {
logger.info("获取学生 " + studentId);
ModelAndView model = new ModelAndView();
model.setViewName("/admin/student/studentedit");
StudentInfo student = studentInfoService.getStudentById(studentId);
model.addObject("student", student);
List<ClassInfo> classes = classInfoService.getClasses(null);
model.addObject("classes", classes);
student.setClassInfo(classInfo);
}
if (gradeId != null) {
grade.setGradeId(gradeId);
student.setGrade(grade);
}
Map<String, Object> map = new HashMap<String, Object>();
//计算当前查询起始数据索引
int startIndex = (startPage-1) * pageShow;
map.put("student", student);
map.put("startIndex", startIndex);
map.put("pageShow", pageShow);
List<StudentInfo> students = studentInfoService.getStudents(map);
model.addObject("students", students);
//获取学生总量
int studentTotal = studentInfoService.getStudentTotal();
//计算总页数
int pageTotal = 1;
if (studentTotal % pageShow == 0)
pageTotal = studentTotal / pageShow;
else
pageTotal = studentTotal / pageShow + 1;
model.addObject("pageTotal", pageTotal);
model.addObject("pageNow", startPage);
return model;
model.addObject("editClass", classInfo);
List<GradeInfo> grades = gradeInfoService.getGrades();
// 获取不是班主任的教师
teacher.setIsWork(0);
Map<String, Object> map = new HashMap<String, Object>();
map.put("startIndex", null);
map.put("pageShow", null);
map.put("teacher", teacher);
List<TeacherInfo> teachers = teacherInfoService.getTeachers(map);
// 如果没有可用班主任
if (teachers.size() == 0 || teachers == null) {
teacher.setTeacherId(classInfo.getTeacher().getTeacherId());
teacher.setTeacherName("暂无剩余教师");
teachers.add(teacher);
}
model.addObject("teachers", teachers);
model.addObject("grades", grades);
return model;
}
/**
* 修改班级信息
*
* @param classInfo
* 班级信息
* @param request
* @param lastTeacherId
* 上一个班主任编号,修改其 班主任状态
@Controller
@SuppressWarnings("all")
public class StudentInfoHandler {
@Autowired
private StudentInfoService studentInfoService;
@Autowired
private ClassInfoService classInfoService;
@Autowired
private ExamSubjectMiddleInfoService examSubjectMiddleInfoService;
@Autowired
private ExamHistoryPaperService examHistoryPaperService;
@Autowired
private ExamChooseInfoService examChooseInfoService;
@Autowired
private ExamSubjectMiddleInfo esm;
@Autowired
private ClassInfo classInfo;
@Autowired
*/
@RequestMapping(value = "/student/student", method = RequestMethod.POST)
public String isUpdateOrAddCourse(
@RequestParam(value = "studentId", required = false) Integer studentId,
@RequestParam(value = "isupdate", required = false) Integer isUpdate,
@RequestParam(value = "studentName", required = false) String studentName,
@RequestParam("studentAccount") String studentAccount,
@RequestParam("studentPwd") String studentPwd,
@RequestParam("classId") Integer classId) {
StudentInfo student = new StudentInfo();
student.setStudentId(studentId);
student.setStudentName(studentName);
student.setStudentAccount(studentAccount);
student.setStudentPwd(studentPwd);
classInfo.setClassId(classId);
student.setClassInfo(classInfo);
if (isUpdate != null) {
logger.info("修改学生 " + student + " 的信息");
int row = studentInfoService.isUpdateStudent(student);
} else {
logger.info("添加学生 " + student + " 的信息");
int row = studentInfoService.isAddStudent(student);
}
return "redirect:/students";
String returnMsg = isChangeTeacherWork(1, classInfo.getTeacher().getTeacherId());
if (returnMsg != null) {
request.setAttribute("error", "修改教师班主任状态 对应教师编号有误");
return "../error";
}
int row = classInfoService.isUpdateClass(classInfo);
if (row < 1) {
logger.error("班级 " + classInfo + " 修改失败");
request.setAttribute("error", "班级修改失败,请稍后再试!");
return "../error";
}
return "redirect:/classes";
}
/**
* 获取指定系部下的班级
*
* @param gradeId
* 系部编号
* @param response
* @throws IOException
*/
@RequestMapping(value = "/gradeclass/{gradeId}", method = RequestMethod.GET)
public void getClassesByGradeId(@PathVariable("gradeId") Integer gradeId, HttpServletResponse response)
throws IOException {
List<ClassInfo> classes = classInfoService.getClassByGradeId(gradeId);
@RequestParam(value = "isupdate", required = false) Integer isUpdate,
@RequestParam("teacherName") String teacherName, @RequestParam("teacherAccount") String teacherAccount,
@RequestParam("teacherPwd") String teacherPwd, @RequestParam("adminPower") Integer adminPower) {
TeacherInfo teacher = new TeacherInfo();
teacher.setTeacherId(teacherId);
teacher.setTeacherName(teacherName);
teacher.setTeacherAccount(teacherAccount);
teacher.setTeacherPwd(teacherPwd);
teacher.setAdminPower(adminPower);
if (isUpdate != null) { // 修改
logger.info("修改教师 " + teacher + " 的信息");
int row = teacherInfoService.isUpdateTeacherInfo(teacher);
} else { // 添加
logger.info("添加教师 " + teacher + " 的信息");
int row = teacherInfoService.isAddTeacherInfo(teacher);
}
return "redirect:/teachers";