基于javaweb+mysql的ssm+maven课程在线学习与测试系统(java+ssm+redis+bootstrap+html+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven课程在线学习与测试系统(java+ssm+redis+bootstrap+html+mysql)
基于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
项目亮点
- 前后端分离。
- 用户登录权限区分和控制。
- 防止横向越权和纵向越权。
- 设计高复用的服务器响应对象。
- guava缓存。
- pojo,vo抽象模型。
- 数据绑定对象。
- Mybatis分页
- Bootstrap。
- artTemplate,artDialog,iframe前端模板使用。
- select2、toastr、sweetalert等等前端插件的使用。
- redis缓存。
- 全局异常处理,拦截器权限统一检验。
/**
* @description 学生交卷,计算分数
*/
@RequestMapping("submitPaper.do")
@ResponseBody
public ServerResponse submitPaper(HttpServletRequest request, Integer pkPaper, String testsAndAnswer) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String studentStr = RedisPoolUtil.get(token);
Student student = JacksonUtil.stringToObj(studentStr, Student.class);
if (student == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
return studentService.submitPaper(pkPaper, student, testsAndAnswer);
}
/**
* @description 学生查询成绩
*/
@RequestMapping("inquiryScore.do")
@ResponseBody
public ServerResponse inquiryScore(HttpServletRequest request) {
//判断登录
try {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String studentStr = RedisPoolUtil.get(token);
Student student = JacksonUtil.stringToObj(studentStr, Student.class);
if (student == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
return studentService.inquiryScore(student);
} catch (Exception e) {
}
/**
* @description 删除教师关联班级
*/
@RequestMapping("delRelTeacherMajor.do")
@ResponseBody
public ServerResponse delRelTeacherMajor(HttpServletRequest request, Integer pkTeacher, Integer pkMajor) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
log.info(manager.getPkManager() + "执行了删除教师:" + pkTeacher + " 关联的:" + pkMajor + " 专业的操作");
return manageService.delRelTeacherMajor(pkTeacher, pkMajor);
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
/**
* @description 获取年级
*/
@RequestMapping("getGrade.do")
@ResponseBody
public ServerResponse getGrade(HttpServletRequest request) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_TEACHER.equals(teacher.getRole())) {
return paperService.modifyPublicFlag(pkPaper, flag, teacher);
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 修改有效状态
*/
@RequestMapping("modifyFlag.do")
@ResponseBody
public ServerResponse modifyFlag(HttpServletRequest request, Integer pkPaper, String flag) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_TEACHER.equals(teacher.getRole())) {
return paperService.modifyFlag(pkPaper, flag, teacher);
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 试卷预览
*/
@RequestMapping("paperDetail.do")
@ResponseBody
public ServerResponse paperDetail(HttpServletRequest request, Integer pkPaper) {
//判断登录
String token = CookieUtil.readCookie(request);
**/
@Controller
@RequestMapping("/notice/")
public class NoticeController {
@Autowired
private NoticeService noticeService;
/**
* @description 获取有效通知内容,用于首页展示
*/
@RequestMapping("showNotice.do")
@ResponseBody
public ServerResponse showNotice(HttpServletRequest request, Notice notice,
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "100") int pageSize) {
//判断用户是否登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String userStr = RedisPoolUtil.get(token);
if (StringUtils.isBlank(userStr)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
notice.setFlag("Y");
return noticeService.queryNotice(notice, pageNum, pageSize);
}
/**
* @description 查询通知
*/
@RequestMapping("queryNotice.do")
@ResponseBody
public ServerResponse queryNotice(HttpServletRequest request, Notice notice,
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
//判断登录
OutputStream toClient = null;
try {
String path = request.getServletContext().getRealPath("") + "\\file\\download\\" + fileName;
File file = new File(path);
String filename = file.getName();
fis = new BufferedInputStream(new FileInputStream(path));
response.reset();
response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
response.setContentType("application/octet-stream");
toClient = new BufferedOutputStream(response.getOutputStream());
IOUtils.copy(fis, toClient);
} catch (Exception e) {
log.error("下载文件出错", e);
return ServerResponse.createByErrorMessage("下载文件出错");
} finally {
try {
assert fis != null;
assert toClient != null;
fis.close();
toClient.flush();
toClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return ServerResponse.createBySuccessMessage("下载文件成功");
}
/**
* @description 上传文件
*/
@RequestMapping(value = "upFile.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse upFile(HttpServletRequest request, MultipartFile multipartFile, String className) {
if (multipartFile == null) {
return ServerResponse.createByErrorMessage("文件不能为空");
}
if (StringUtils.isBlank(className)) {
return ServerResponse.createByErrorMessage("系统错误");
}
try {
String path = request.getServletContext().getRealPath("") + "\\file\\upload";
String fileName = multipartFile.getOriginalFilename();
File file = new File(path, fileName);
//MultipartFile自带的解析方法
multipartFile.transferTo(file);
Class<?> clazz = Class.forName(className);
* @description 新增或更新通知
*/
@RequestMapping("addOrModifyNotice.do")
@ResponseBody
public ServerResponse addOrModifyNotice(HttpServletRequest request, Notice notice) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
return noticeService.addOrModifyNotice(notice, manager);
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
/**
* @description 获取单条通知内容
*/
@RequestMapping("getNotice.do")
@ResponseBody
public ServerResponse getNotice(HttpServletRequest request, Integer pkNotice) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
return noticeService.getNotice(pkNotice);
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
}
*/
@RequestMapping("getTeacherMajor.do")
@ResponseBody
public ServerResponse getTeacherMajor(HttpServletRequest request, Integer pkTeacher,
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
return manageService.getTeacherMajor(pkTeacher, pageNum, pageSize);
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
/**
* @description 获取专业信息&&查询专业
*/
@RequestMapping("queryMajor.do")
@ResponseBody
public ServerResponse queryMajor(HttpServletRequest request, Major major,
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
return manageService.addRelTeacherMajor(pkTeacher, pkMajor, manager);
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
/**
* @description 删除教师关联班级
*/
@RequestMapping("delRelTeacherMajor.do")
@ResponseBody
public ServerResponse delRelTeacherMajor(HttpServletRequest request, Integer pkTeacher, Integer pkMajor) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
log.info(manager.getPkManager() + "执行了删除教师:" + pkTeacher + " 关联的:" + pkMajor + " 专业的操作");
return manageService.delRelTeacherMajor(pkTeacher, pkMajor);
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
/**
* @description 获取年级
return studentService.getPaperDetail(pkPaper, student);
}
/**
* @description 学生交卷,计算分数
*/
@RequestMapping("submitPaper.do")
@ResponseBody
public ServerResponse submitPaper(HttpServletRequest request, Integer pkPaper, String testsAndAnswer) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String studentStr = RedisPoolUtil.get(token);
Student student = JacksonUtil.stringToObj(studentStr, Student.class);
if (student == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
return studentService.submitPaper(pkPaper, student, testsAndAnswer);
}
/**
* @description 学生查询成绩
*/
@RequestMapping("inquiryScore.do")
@ResponseBody
public ServerResponse inquiryScore(HttpServletRequest request) {
//判断登录
try {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String studentStr = RedisPoolUtil.get(token);
Student student = JacksonUtil.stringToObj(studentStr, Student.class);
if (student == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
return studentService.inquiryScore(student);
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_TEACHER.equals(teacher.getRole())) {
return paperService.modifyFlag(pkPaper, flag, teacher);
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 试卷预览
*/
@RequestMapping("paperDetail.do")
@ResponseBody
public ServerResponse paperDetail(HttpServletRequest request, Integer pkPaper) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_TEACHER.equals(teacher.getRole())) {
return paperService.paperDetail(pkPaper, teacher);
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 手动组卷, 添加试题
*/
@RequestMapping("compositionPaper.do")
@ResponseBody
public ServerResponse compositionPaper(HttpServletRequest request, PaperDetail paperDetail) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
/**
* @description 已登录,重置密码
*/
@RequestMapping(value = "resetPassword.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse<String> resetPassword(HttpServletRequest request, String passwordOld, String passwordNew) {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
return teacherService.resetTeacherPassword(passwordNew, passwordOld, teacher);
}
/**
* @description 设置或更新找回密码问题和答案
*/
@RequestMapping(value = "updateTeacherInformation.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse updateTeacherInformation(HttpServletRequest request, String question, String answer) {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
return teacherService.updateTeacherInformation(question, answer, teacher);
}
/**
* @description 获取教师管理的专业信息
*/
@RequestMapping(value = "getTeacherMajor.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse getTeacherMajor(HttpServletRequest request) {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 获取单试题信息
*/
@RequestMapping("getTestsInfo.do")
@ResponseBody
public ServerResponse getTestsInfo(HttpServletRequest request, Integer pkTest) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_TEACHER.equals(teacher.getRole())) {
return testsService.getTestsInfo(pkTest);
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 新增试题
*/
@RequestMapping("addTest.do")
@ResponseBody
public ServerResponse addTest(HttpServletRequest request, Tests tests) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
return manageService.getGrade();
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
/**
* @description 获取指定年级下专业
*/
@RequestMapping("getMajor.do")
@ResponseBody
public ServerResponse getMajor(HttpServletRequest request, String grade) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
if (manager == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_ADMIN.equals(manager.getRole())) {
return manageService.getMajor(grade);
}
return ServerResponse.createByErrorMessage("不是管理员,无法操作");
}
/**
* @description 获取教师关联的专业信息
*/
@RequestMapping("getTeacherMajor.do")
@ResponseBody
public ServerResponse getTeacherMajor(HttpServletRequest request, Integer pkTeacher,
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "5") int pageSize) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String manageStr = RedisPoolUtil.get(token);
Manager manager = JacksonUtil.stringToObj(manageStr, Manager.class);
/**
* @name PaperController
* @description
**/
@Controller
@RequestMapping("/paper/")
public class PaperController {
@Autowired
private PaperService paperService;
/**
* @description 查询试卷
*/
@RequestMapping("queryPaper.do")
@ResponseBody
public ServerResponse queryPaper(HttpServletRequest request, Paper paper,
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_TEACHER.equals(teacher.getRole())) {
return testsService.addTest(tests, teacher);
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 修改试题状态
*/
@RequestMapping("modifyTestFlag.do")
@ResponseBody
public ServerResponse modifyTestFlag(HttpServletRequest request, Integer pkTest, String flag) {
//判断登录
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
//判断权限,业务处理
if (Constant.Role.ROLE_TEACHER.equals(teacher.getRole())) {
return testsService.modifyTestFlag(pkTest, flag, teacher);
}
return ServerResponse.createByErrorMessage("不是教师,无法操作");
}
/**
* @description 查询科目列表
*/
@RequestMapping("selectSubjectList.do")
@ResponseBody
public ServerResponse selectSubjectList(HttpServletRequest request) {
//判断登录
String token = CookieUtil.readCookie(request);
* @description 用户登录
*/
@RequestMapping(value = "login.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse login(String username, String password, HttpSession session, HttpServletResponse response) {
//验证用户登录信息是否正确
ServerResponse sr = teacherService.login(username, password);
//验证通过,将当前用户信息放入session
if (sr.isSuccess()) {
CookieUtil.writeCookie(response, session.getId());
RedisPoolUtil.setEx(session.getId(), JacksonUtil.objToString(sr.getData()), 60 * 30);
}
return sr;
}
/**
* @description 获取用户信息
*/
@RequestMapping(value = "getUserName.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse getUserName(HttpServletRequest request) {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String teacherStr = RedisPoolUtil.get(token);
Teacher teacher = JacksonUtil.stringToObj(teacherStr, Teacher.class);
if (teacher != null) {
return ServerResponse.createBySuccess(teacher);
}
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
/**
* @description 未登录:忘记密码,获取问题
*/
@RequestMapping(value = "forgetGetQuestion.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse<String> forgetGetQuestion(String username) {
return teacherService.selectQuestion(username);
}
/**
* @description 未登录:忘记密码,检查答案是否正确
/**
* @description 未登录:忘记密码,检查答案是否正确
*/
@RequestMapping(value = "forgetCheckAnswer.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse<String> forgetCheckAnswer(String username, String question, String answer) {
return studentService.checkAnswer(username, question, answer);
}
/**
* @description 未登录:忘记密码,重置密码
*/
@RequestMapping(value = "forgetResetPassword.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse<String> forgetRestPassword(String username, String passwordNew, String forgetToken) {
return studentService.forgetResetPassword(username, passwordNew, forgetToken);
}
/**
* @description 已登录,重置密码
*/
@RequestMapping(value = "resetPassword.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse<String> resetPassword(HttpServletRequest request, String passwordOld, String passwordNew) {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
String studentStr = RedisPoolUtil.get(token);
Student student = JacksonUtil.stringToObj(studentStr, Student.class);
if (student == null) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");
}
return studentService.resetStudentPassword(passwordNew, passwordOld, student);
}
/**
* @description 设置或更新找回密码问题和答案
*/
@RequestMapping(value = "updateStudentInformation.do", method = RequestMethod.POST)
@ResponseBody
public ServerResponse updateStudentInformation(HttpServletRequest request, String question, String answer) {
String token = CookieUtil.readCookie(request);
if (StringUtils.isEmpty(token)) {
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "请先登录");