源码获取:博客首页 "资源" 里下载!

一、项目简述

功能列表 考试前台 /系统登录:学生、教师、管理员登录 /门户首页:无需认证访问 /在线考试:需认证即可查看当前考除目 /题库中心:需认证查看题库 /成绩查询:需认证查询成绩 /留言板:需认证留言 管理后台 /考:署理:发布考试,考试列表,课程管理,题库管 理,成绩管理,成绩情况 /权限管理:学院管理,班级管理,用户管理,角色管 理,资源管理 4网站管理:基础信息,友链管理,评论管理,标签管理 /系统管理:在线用户 /上传管理:云存储配置 /运维管理:数据监控

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +SpringBoot + MyBatis + Redis+ Thymeleaf+ Druid+ JQuery + SLF4J+ Fileupload + maven等等

班级信息控制器:

@Controller
@RequestMapping("classes")
public class ClassesController {
	
	@Autowired
	private ClassesService classesService;
	
	@Autowired
	private InstituteService instituteService;
	
	@PostMapping("list")
	@ResponseBody
	public PageResultVo loadClasses(ClassesConditionVo classesConditionVo, Integer limit, Integer offset) {
		PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
		List<Classes> classesList = classesService.findByCondition(classesConditionVo);
		PageInfo<Classes> pages = new PageInfo<>(classesList);
		return ResultUtil.table(classesList, pages.getTotal(), pages);
	}
	
	/**
	 * 新增班级
	 * @param classes
	 * @return
	 */
	@PostMapping("/add")
	@ResponseBody
	public ResponseVo add(Classes classes) {
		User user = (User)SecurityUtils.getSubject().getPrincipal();
		classes.setAuthor(user.getNickname());
		Date date = new Date();
		classes.setCreateTime(date);
		classes.setUpdateTime(date);
		classes.setStatus(CoreConst.STATUS_INVALID);
		
		int i = classesService.insert(classes);
		if(i > 0) {
			return ResultUtil.success("新增班级信息成功");
		}else {
			return ResultUtil.error("新增班级信息失败");
		}
	}

	/**
	 * 更新班级信息
	 * @param model
	 * @param id
	 * @return
	 */
	@GetMapping("/edit")
	public String edit(Model model,Integer id) {
		Classes classes = classesService.selectById(id);
		List<Institute> institutes = instituteService.selectAll();
    	model.addAttribute("institutes",institutes);
		model.addAttribute("classes", classes);
		return "classes/detail";
	}
	
	@PostMapping("/edit")
	@ResponseBody
	public ResponseVo edit(Classes classes) {
		int i = classesService.updateNotNull(classes);
		if(i > 0) {
			return ResultUtil.success("更新班级信息成功");
		}else {
			return ResultUtil.error("更新班级信息失败");
		}
	}
	
	/**
	 * 删除班级信息
	 * @param id
	 * @return
	 */
	@PostMapping("/delete")
	@ResponseBody
	public ResponseVo delete(Integer id) {
		//验证班级下是否有学生
		int i = classesService.validateByClassIds(new Integer[] {id});
		if(i > 0) {
			return ResultUtil.error("无法删除,该班级中还有学生");
		}else {
			int j = classesService.deleteBatch(new Integer[] {id});
			if(j > 0) {
				return ResultUtil.success("删除班级信息成功");
			}else {
				return ResultUtil.error("删除班级信息 失败");
			}
		}
	}
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@PostMapping("/batch/delete")
	@ResponseBody
	public ResponseVo deleteBatch(@RequestParam("ids[]") Integer[]ids) {
		//验证该班级中是否有学生
		int i = classesService.validateByClassIds(ids);
		if(i > 0) {
			return ResultUtil.error("无法批量删除,该班级中还有学生");
		}else {
			int j = classesService.deleteBatch(ids);
			if(j > 0) {
				return ResultUtil.success("批量删除班级信息成功");
			}else {
				return ResultUtil.error("批量删除班级信息失败");
			}
		}
	}
	
	
}

评论控制层:

@RestController
@RequestMapping("comment")
public class CommentController {

    @Autowired
    private CommentService commentService;
    

    @PostMapping("list")
    public PageResultVo loadNotify(CommentConditionVo comment, Integer limit, Integer offset){
        PageHelper.startPage(PageUtil.getPageNo(limit, offset),limit);
        List<Comment> comments = commentService.selectComments(comment);
        PageInfo<Comment> pages = new PageInfo<>(comments);
        return ResultUtil.table(comments,pages.getTotal(),pages);
    }
    
    
    @PostMapping("/reply")
    public ResponseVo edit(Comment comment){
        completeComment(comment);
        int i = commentService.insertSelective(comment);
        if(i>0){
            return ResultUtil.success("回复评论成功");
        }else{
            return ResultUtil.error("回复评论失败");
        }
    }
   
    
    @PostMapping("/delete")
    public ResponseVo delete(Integer id){
        Integer[]ids={id};
        int i = commentService.deleteBatch(ids);
        if(i>0){
            return ResultUtil.success("删除评论成功");
        }else{
            return ResultUtil.error("删除评论失败");
        }
    }
    @PostMapping("/batch/delete")
    public ResponseVo deleteBatch(@RequestParam("ids[]") Integer[]ids){
        int i = commentService.deleteBatch(ids);
        if(i>0){
            return ResultUtil.success("删除评论成功");
        }else{
            return ResultUtil.error("删除评论失败");
        }
    }

    @PostMapping("/audit")
    public ResponseVo audit(Comment bizComment, String replyContent){
        try {
            commentService.updateNotNull(bizComment);
            if(StringUtils.isNotBlank(replyContent)){
                Comment replyComment = new Comment();
                replyComment.setPid(bizComment.getId());
                replyComment.setSid(bizComment.getSid());
                replyComment.setContent(replyContent);
                completeComment(replyComment);
                commentService.insertSelective(replyComment);
            }
            return ResultUtil.success("审核成功");
        } catch (Exception e) {
            return ResultUtil.success("审核失败");
        }
    }

    private void completeComment(Comment comment){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        User user = (User)SecurityUtils.getSubject().getPrincipal();
        comment.setUserId(user.getUserId());
        comment.setNickname(user.getNickname());
        comment.setEmail(user.getEmail());
        comment.setAvatar(user.getImg());
        comment.setIp(IpUtil.getIpAddr(request));
        comment.setStatus(CoreConst.STATUS_VALID);
    }

}

用户信息控制层:

@Controller
@RequestMapping("/online/user")
public class OnlineUserController {
    @Autowired
    private UserService userService;

    // 在线用户列表
    @PostMapping("/list")
    @ResponseBody
    public PageResultVo onlineUsers(UserOnlineVo user, Integer limit, Integer offset){
        List<UserOnlineVo> userList = userService.selectOnlineUsers(user);
        PageInfo<UserOnlineVo> pages = new PageInfo<>(userList);
        int endIndex = (offset+limit) > userList.size() ? userList.size() : (offset+limit);
        return ResultUtil.table(userList.subList(offset,endIndex),(long)userList.size(),pages);
    }

    // 强制踢出用户
    @PostMapping("/kickout")
    @ResponseBody
    public ResponseVo kickout(String sessionId,String username) {
        try {
            if(SecurityUtils.getSubject().getSession().getId().equals(sessionId)){
                return ResultUtil.error("不能踢出自己");
            }
            userService.kickout(sessionId,username);
            return ResultUtil.success("踢出用户成功");
        } catch (Exception e) {
            return ResultUtil.error("踢出用户失败");
        }
    }

    // 批量强制踢出用户
    @PostMapping("/batch/kickout")
    @ResponseBody
    public ResponseVo kickout(@RequestBody List<UserSessionVo> sessions) {
        try {
            //要踢出的用户中是否有自己
            boolean hasOwn=false;
            Serializable sessionId = SecurityUtils.getSubject().getSession().getId();
            for (UserSessionVo sessionVo : sessions) {
                if(sessionVo.getSessionId().equals(sessionId)){
                    hasOwn=true;
                }else{
                    userService.kickout(sessionVo.getSessionId(),sessionVo.getUsername());
                }


            }
            if(hasOwn){
                return ResultUtil.success("不能踢出自己");
            }
            return ResultUtil.success("踢出用户成功");
        } catch (Exception e) {
            return ResultUtil.error("踢出用户失败");
        }
    }
}

 源码获取:博客首页 "资源" 里下载!

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐