基于SSM实现学生竞赛管理系统
Posted 编程指南针
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于SSM实现学生竞赛管理系统相关的知识,希望对你有一定的参考价值。
作者主页:编程指南针
作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师
主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助
文末获取源码
项目编号:BS-XX-044
前言:
为方便各高校对在校园内举办的各类竞赛进行有效的管理,我设计了这套基于SSM实现的竞赛管理系统。我所设计的这套竞赛管理系统,就是基于这样一个时代背景应运而且,一是可以大大降低各高校对于校内所举办的各项竞赛管理的各项成本;二是可以大大提高各类竞赛信息管理的效率。使用计算机对竞赛进行管理的优点如:检索迅速、查找方便、易修改、存储量大、保密性好、成本低等。因此,建立一个规范、合理、实用、有效的竞赛管理系统对竞赛资料进行集中统一的管理就显得格外重要。目前来看,在政府、工商业、学校、企事业单位等单位中,每年都会举办一些各式各样的竞赛活动,几乎都会应用竞赛管理系统进行信息化管理。通过信息化的手段在竞赛管理中加入计算机软件的应用,本质上其实就是对于竞赛相关信息进行管理。利用管理信息系统对竞赛馆的竞赛进行有效的管理,可以大大提高竞赛管理竞赛管理的效率,提升使用的方便性以及其安全性。
本竞赛管理系统本质上利用了信息管理系统的基本思想,综合应用了基于软件开发JAVA相关技术,并以关系型数据库mysql作为数据存储的基本手段,主要实现了竞赛管理员对竞赛活动、竞赛作品、以及参赛用户信息和相关评委信息进行存储和管理,并实现了对相关信息基本的增、删、改、查的基本操作功能,这样就可以很好的提升竞赛相关信息的管理质量,提升系统参与的用户的体验感。
一,项目简介
竞赛管理系统的使用者主要包含三种用户角色,其一是管理员角色,其二是参赛用户角色,其三是竞赛评委角色,评委可以指定教师或外部工程师。这三个角色的具体功能如下:
管理员角色:管理员登录竞赛管理系统后可以进行相应的管理操作,主要包含:学生用户管理、竞赛活动管理、老师管理、工程师管理、个人信息管理、账户密码重置等操作。
参赛用户角色:参赛用户登录竞赛管理系统后可以进行参与相关竞赛、提交和下载个人竞赛作品、个人信息管理等操作。
评委用户角色:竞赛中指定的活动评委,可以登陆系统对担任评委的竞赛活动的作品进行评分操作。
根据上述对系统的功能性需求分析,设计出了竞赛管理系统的功能结构图,如下图3-1所示:
图3-1 系统功能结构图
系统简单性原则:系统操作界面应尽量简单易行,让非专业的系统使用者能够快速上手,符合用户常用的操作习惯,不要设计过多复杂的操作。
系统针对性原则:通过对高校竞赛管理人员日常参与竞赛管理的基本流程的调查研究,开发并设计了竞赛管理系统,所以本系统面向的主要是竞赛参与的相关人员。另外就是针对竞赛的管理用户使用,让他们能够方便的进行竞赛评分和人员管理操作,并方便的进行相关信息的查询。
系统实用性原则:竞赛系统所具有的功能都是与竞赛活动有关,对竞赛活的管理者和参赛用户都具有一定的帮助性和实用性。
系统一致性原则:竞赛系统页面的设计采用了统一的风格,操作规则也进行了统一,数据显示也大致相同的,对于系统管理者和前端用户的操作均简单易懂。
系统先进性原则:本系统采用了SSM框架,JSP技术、Mysql数据库,这些都是目前企业开发中使用较多的开发技术和数据库服务器,并且使用了B/S架构模式和三层结构设计,这就使竞赛管理系统具有良好的可扩展性和灵活性。
二,环境介绍
语言环境:Java: jdk1.8
数据库:Mysql: mysql5.7
应用服务器:Tomcat: tomcat8.5.31
开发工具:IDEA或eclipse
后台开发技术:SSM框架
前端开发技术:Bootstrap+Jquery+Ajax
三,系统展示
6.1 管理员后台管理功能模块的展示
6.1.1 作品分类管理模块
作品分类管理主要包含读者信息管理,管理员登录后台进入作品分类管理操作界面,在此模块可以查看分类信息,可以对作品分类信息进行相关管理操作,主要包含作品分类信息添加、作品分类管理修改、作品分类管理删除、作品分类管理查询的管理操作。界面展示如下图6-1所示:
图6-1 作品分类管理操作实现界面
6.1.2参赛作品管理模块
参赛作品管理模块主要是对参加竞赛的作品管理,系统管理员登录后台系统后,进入参赛作品管理操作界面,可以在此对参赛作品进行相关的管理操作,主要包含对参赛作品的信息查看、修改、删除、评分的相关操作。参赛作品管理操作界面如下图6-2所示:
图6-2 参赛作品管理操作界面
6.1.3 竞赛管理模块
竞赛管理模块主要包含竞赛活动的相关管理操作,系统管理员登录系统,进入竞赛管理操作界面,主要包含竞赛活动添加、竞赛活动查询、竞赛活动的状态管理操作。添加竞赛活动时可以指定此活动的评委。相关管理操作界面如下图6-3所示:
图6-3竞赛管理操作界面
6.1.4工程师信息管理模块
工程师信息管理模块主要包含对作为评委的企业工程师信息进行管理,评委可以是教师也可以是企业的工程师。系统管理员登录系统后,可以进入工程师信息管理界面进行相关管理操作,主要包含对工程师的添加、修改、删除和查询的相关管理操作。后台工程师管理模块的相关管理操作界面如下图6-4所示:
图6-4后台工程师管理操作界面
6.1.5学生信息管理模块
学生信息管理模块主要包含对学生信息进行管理,学生信息在系统登陆界面进行注册,在此后台模块也可以实施添加操作。系统管理员登录系统后,可以进入学生信息管理界面进行相关管理操作,主要包含对学生的添加、修改、删除和查询的相关管理操作。后台学生管理模块的相关管理操作界面如下图6-5所示:
图6-5学生管理操作界面
6.1.6老师信息管理模块
老师信息管理模块主要包含对老师信息进行管理,老师可以做为活动的指定评委参与参赛作品的评分操作。系统管理员登录系统后,可以进入老师信息管理界面进行相关管理操作,主要包含对老师的添加、修改、删除和查询的相关管理操作。后台老师管理模块的相关管理操作界面如下图6-6所示:
图6-6老师管理操作界面
6.1.7用户信息重置管理模块
用户信息重置管理模块主要是对相关用户的密码等信息进行重置,以防止用户忘记密码操作。系统管理员登录系统后,可以进入密码重置信息管理界面进行相关管理操作,主要包含对老师、学生、工程等的密码重置操作。后台密码重置管理模块的相关管理操作界面如下图6-7所示:
6.2学生用户功能模块的展示
6.2.1用户登录功能
用户如果想要进行竞赛参与,首先要登录系统,才可展开相关的竞赛操作。用户登陆界面如下图6-8所示:
图6-8用户登录操作界面
6.2.3学生参与竞赛功能
学生登陆系统后可以在竞赛功能模块中查看当前竞赛活动的列表,并显示当前用户是否可以参与当前竞赛,规则是一次竞赛一个学生只能参与一次,如果已经参与过,将不能再次参与。参与竞赛时上传自己的参赛作品。操作界面如下图6-10所示:
图6-10学生用户参与竞赛功能界面
四,核心代码展示
package com.system.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.system.exception.CustomException;
import com.system.po.*;
import com.system.service.*;
import org.apache.commons.io.FileUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/admin")
public class AdminController
@Resource(name = "studentServiceImpl")
private StudentService studentService;
@Resource(name = "teacherServiceImpl")
private TeacherService teacherService;
//注入院系业务实现类
@Resource(name = "collegeServiceImpl")
private CollegeService collegeService;
@Resource(name = "userloginServiceImpl")
private UserloginService userloginService;
@Resource(name = "competitionServiceImpl")
private CompetitionService competitionService;
@Resource(name = "productionTypeServiceImpl")
private ProductionTypeService productionTypeService;
@Resource(name = "productionServiceImpl")
private ProductionService productionService;
@Resource(name = "engineerServiceImpl")
private EngineerService engineerService;
// 工程师信息显示
@RequestMapping("/showEngineer")
public String showUser(Model model, Integer page) throws Exception
List<Engineer> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(engineerService.getCountEngineer());
if (page == null || page == 0)
pagingVO.setToPageNo(1);
list = engineerService.findByPaging(1);
else
pagingVO.setToPageNo(page);
list = engineerService.findByPaging(page);
model.addAttribute("engineerList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showEngineer";
//搜索竞赛信息
@RequestMapping(value = "selectEngineer", method = RequestMethod.POST)
private String selectEngineer(String findByName, Model model) throws Exception
List<Engineer> list = engineerService.findByName(findByName);
model.addAttribute("engineerList", list);
return "admin/showEngineer";
/**
* 添加工程師信息页面显示
*/
@RequestMapping(value = "/addEngineer", method = RequestMethod.GET)
public String addEngineerUI(Model model) throws Exception
List<College> list = collegeService.finAll();
model.addAttribute("collegeList", list);
return "admin/addEngineer";
/**
* 添加工程师信息操作
*/
@RequestMapping(value = "/addEngineer", method = RequestMethod.POST)
public String addEngineer(Engineer engineer, Model model) throws Exception
if (engineer.getUserid() == null)
model.addAttribute("message", "工号不能为空");
return "error";
if (StrUtil.isBlank(engineer.getUsername()))
model.addAttribute("message", "姓名不能为空");
return "error";
if (StrUtil.isBlank(engineer.getEnterprisename()))
model.addAttribute("message", "公司名称不能为空");
return "error";
Engineer engineer1 = engineerService.findById(engineer.getUserid());
if (engineer1 != null)
model.addAttribute("message", "工号重复");
return "error";
//先根据工号查询登陆数据库中是否有此工号,无此工号才能添加
Userlogin userLogin = userloginService.findByName(engineer.getUserid().toString());
if(userLogin!=null)
model.addAttribute("message", "工号重复");
return "error";
Boolean result = engineerService.save(engineer);
if (!result)
model.addAttribute("message", "工程师信息重复");
return "error";
//添加成功后,也添加到登录表
Userlogin userlogin = new Userlogin();
userlogin.setUsername(String.valueOf(engineer.getUserid()));
userlogin.setPassword("123");
userlogin.setRole(3);
userloginService.save(userlogin);
//重定向
return "redirect:/admin/showEngineer";
// 修改工程师信息页面显示
@RequestMapping(value = "/editEngineer", method = RequestMethod.GET)
public String editEngineerUI(Integer id, Model model) throws Exception
if (id == null)
return "redirect:/admin/showEngineer";
Engineer engineer = engineerService.findById(id);
if (engineer == null)
throw new CustomException("未找到该名学生");
// List<College> list = collegeService.finAll();
// model.addAttribute("collegeList", list);
model.addAttribute("engineer", engineer);
return "admin/editEngineer";
// 修改工程师信息页面处理
@RequestMapping(value = "/editEngineer", method = RequestMethod.POST)
public String editEngineer(Engineer engineer, Model model) throws Exception
if (engineer.getUserid() == null)
model.addAttribute("message", "工号不能为空");
return "error";
if (StrUtil.isBlank(engineer.getUsername()))
model.addAttribute("message", "姓名不能为空");
return "error";
if (StrUtil.isBlank(engineer.getEnterprisename()))
model.addAttribute("message", "公司名称不能为空");
return "error";
engineerService.updataById(engineer.getUserid(), engineer);
//重定向
return "redirect:/admin/showEngineer";
// 删除工程师
@RequestMapping(value = "/removeEngineer", method = RequestMethod.GET )
private String removeEngineer(Integer id) throws Exception
if (id == null)
//加入没有带学生id就进来的话就返回学生显示页面
return "admin/showStudent";
engineerService.removeById(id);
userloginService.removeByName(id.toString());
return "redirect:/admin/showEngineer";
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<学生操作>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
// 学生信息显示
@RequestMapping("/showStudent")
public String showStudent(Model model, Integer page) throws Exception
List<StudentCustom> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(studentService.getCountStudent());
if (page == null || page == 0)
pagingVO.setToPageNo(1);
list = studentService.findByPaging(1);
else
pagingVO.setToPageNo(page);
list = studentService.findByPaging(page);
model.addAttribute("studentList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showStudent";
// 添加学生信息页面显示
@RequestMapping(value = "/addStudent", method = RequestMethod.GET)
public String addStudentUI(Model model) throws Exception
List<College> list = collegeService.finAll();
model.addAttribute("collegeList", list);
return "admin/addStudent";
// 添加学生信息操作
@RequestMapping(value = "/addStudent", method = RequestMethod.POST)
public String addStudent(StudentCustom studentCustom, Model model) throws Exception
if (studentCustom.getUserid() == null)
model.addAttribute("message", "学号不能为空!");
return "error";
if (StrUtil.isBlank(studentCustom.getUsername()))
model.addAttribute("message", "姓名不能为空!");
return "error";
//先根据工号查询登陆数据库中是否有此工号,无此工号才能添加
Userlogin userLogin = userloginService.findByName(studentCustom.getUserid().toString());
if(userLogin!=null)
model.addAttribute("message", "学号重复");
return "error";
Boolean result = studentService.save(studentCustom);
if (!result)
model.addAttribute("message", "学号重复");
return "error";
//添加成功后,也添加到登录表
Userlogin userlogin = new Userlogin();
userlogin.setUsername(studentCustom.getUserid().toString());
userlogin.setPassword("123");
userlogin.setRole(2);
userloginService.save(userlogin);
//重定向
return "redirect:/admin/showStudent";
// 修改学生信息页面显示
@RequestMapping(value = "/editStudent", method = RequestMethod.GET)
public String editStudentUI(Integer id, Model model) throws Exception
if (id == null)
//加入没有带学生id就进来的话就返回学生显示页面
return "redirect:/admin/showStudent";
StudentCustom studentCustom = studentService.findById(id);
if (studentCustom == null)
throw new CustomException("未找到该名学生");
List<College> list = collegeService.finAll();
model.addAttribute("collegeList", list);
model.addAttribute("student", studentCustom);
return "admin/editStudent";
// 修改学生信息处理
@RequestMapping(value = "/editStudent", method = RequestMethod.POST)
public String editStudent(StudentCustom studentCustom, Model model) throws Exception
if (StrUtil.isBlank(studentCustom.getUsername()))
model.addAttribute("message", "姓名不能为空!");
return "error";
studentService.updataById(studentCustom.getUserid(), studentCustom);
//重定向
return "redirect:/admin/showStudent";
// 删除学生
@RequestMapping(value = "/removeStudent", method = RequestMethod.GET )
private String removeStudent(Integer id) throws Exception
if (id == null)
//加入没有带学生id就进来的话就返回学生显示页面
return "admin/showStudent";
studentService.removeById(id);
userloginService.removeByName(id.toString());
return "redirect:/admin/showStudent";
// 搜索学生
@RequestMapping(value = "selectStudent", method = RequestMethod.POST)
private String selectStudent(String findByName, Model model) throws Exception
List<StudentCustom> list = studentService.findByName(findByName);
model.addAttribute("studentList", list);
return "admin/showStudent";
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<教师操作>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
// 教师页面显示
@RequestMapping("/showTeacher")
public String showTeacher(Model model, Integer page) throws Exception
List<TeacherCustom> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(teacherService.getCountTeacher());
if (page == null || page == 0)
pagingVO.setToPageNo(1);
list = teacherService.findByPaging(1);
else
pagingVO.setToPageNo(page);
list = teacherService.findByPaging(page);
model.addAttribute("teacherList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showTeacher";
// 添加教师信息
@RequestMapping(value = "/addTeacher", method = RequestMethod.GET)
public String addTeacherUI(Model model) throws Exception
List<College> list = collegeService.finAll();
model.addAttribute("collegeList", list);
return "admin/addTeacher";
// 添加教师信息处理
@RequestMapping(value = "/addTeacher", method = RequestMethod.POST)
public String addTeacher(TeacherCustom teacherCustom, Model model) throws Exception
if (teacherCustom.getUserid() == null)
model.addAttribute("message", "工号不能为空");
return "error";
if (StrUtil.isBlank(teacherCustom.getUsername()))
model.addAttribute("message", "姓名不能为空");
return "error";
//先根据工号查询登陆数据库中是否有此工号,无此工号才能添加
Userlogin userLogin = userloginService.findByName(teacherCustom.getUserid().toString());
if(userLogin!=null)
model.addAttribute("message", "工号重复");
return "error";
Boolean result = teacherService.save(teacherCustom);
if (!result)
model.addAttribute("message", "工号重复");
return "error";
//添加成功后,也添加到登录表
Userlogin userlogin = new Userlogin();
userlogin.setUsername(teacherCustom.getUserid().toString());
userlogin.setPassword("123");
userlogin.setRole(1);
userloginService.save(userlogin);
//重定向
return "redirect:/admin/showTeacher";
// 修改教师信息页面显示
@RequestMapping(value = "/editTeacher", method = RequestMethod.GET)
public String editTeacherUI(Integer id, Model model) throws Exception
if (id == null)
return "redirect:/admin/showTeacher";
TeacherCustom teacherCustom = teacherService.findById(id);
if (teacherCustom == null)
throw new CustomException("未找到该名学生");
List<College> list = collegeService.finAll();
model.addAttribute("collegeList", list);
model.addAttribute("teacher", teacherCustom);
return "admin/editTeacher";
// 修改教师信息页面处理
@RequestMapping(value = "/editTeacher", method = RequestMethod.POST)
public String editTeacher(TeacherCustom teacherCustom, Model model) throws Exception
if (StrUtil.isBlank(teacherCustom.getUsername()))
model.addAttribute("message", "姓名不能为空");
return "error";
teacherService.updateById(teacherCustom.getUserid(), teacherCustom);
//重定向
return "redirect:/admin/showTeacher";
//删除教师
@RequestMapping("/removeTeacher")
public String removeTeacher(Integer id) throws Exception
if (id == null)
//加入没有带教师id就进来的话就返回教师显示页面
return "admin/showTeacher";
teacherService.removeById(id);
userloginService.removeByName(id.toString());
return "redirect:/admin/showTeacher";
//搜索教师
@RequestMapping(value = "selectTeacher", method = RequestMethod.POST)
private String selectTeacher(String findByName, Model model) throws Exception
List<TeacherCustom> list = teacherService.findByName(findByName);
model.addAttribute("teacherList", list);
return "admin/showTeacher";
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<课程操作>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
// 竞赛分类信息显示
@RequestMapping("/showProductionType")
public String showProductionType(Model model, Integer page) throws Exception
List<ProductionType> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(productionTypeService.getCountProductionType());
if (page == null || page == 0)
pagingVO.setToPageNo(1);
list = productionTypeService.findByPaging(1);
else
pagingVO.setToPageNo(page);
list = productionTypeService.findByPaging(page);
model.addAttribute("productionTypeList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showProductionType";
//添加竞赛分类
@RequestMapping(value = "/addProductionType", method = RequestMethod.GET)
public String addProductionTypeUI(Model model) throws Exception
return "admin/addProductionType";
// 添加竞赛分类信息处理
@RequestMapping(value = "/addProductionType", method = RequestMethod.POST)
public String addProductionType(ProductionType productionType, Model model) throws Exception
String productiontypename = productionType.getProductiontypename();
if (StrUtil.isBlank(productiontypename))
model.addAttribute("message", "作品分类名称不能为空");
return "error";
List<ProductionType> list = productionTypeService.findByName(productiontypename);
if (CollectionUtil.isNotEmpty(list))
model.addAttribute("message", "作品分类名称已存在");
return "error";
Boolean result = productionTypeService.save(productionType);
if (!result)
model.addAttribute("message", "分类信息重复");
return "error";
//重定向
return "redirect:/admin/showProductionType";
// 修改竞赛分类信息页面显示
@RequestMapping(value = "/editProductionType", method = RequestMethod.GET)
public String editProductionTypeUI(Integer id, Model model) throws Exception
if (id == null)
return "redirect:/admin/showProductionType";
ProductionType productionType = productionTypeService.queryById(id);
if (productionType == null)
throw new CustomException("未找到该竞赛分类");
model.addAttribute("productionType", productionType);
return "admin/editProductionType";
// 修改竞赛分类信息页面处理
@RequestMapping(value = "/editProductionType", method = RequestMethod.POST)
public String editProductionType(ProductionType productionType, Model model) throws Exception
String productiontypename = productionType.getProductiontypename();
if (StrUtil.isBlank(productiontypename))
model.addAttribute("message", "作品分类名称不能为空");
return "error";
List<ProductionType> list = productionTypeService.findByName(productiontypename);
if (CollectionUtil.isNotEmpty(list))
ProductionType productionType1 = list.get(0);
if (productionType1.getProductiontypeid() != productionType.getProductiontypeid())
model.addAttribute("message", "作品分类名称已存在");
return "error";
productionTypeService.update(productionType);
//重定向
return "redirect:/admin/showProductionType";
// 删除竞赛分类信息
@RequestMapping("/removeProductionType")
public String removeProductionType(Integer id, Model model) throws Exception
if (id == null)
//加入没有带教师id就进来的话就返回教师显示页面
return "/admin/showProductionType";
List<Competition> competitions = competitionService.queryProductionTypeId(id);
if (CollectionUtil.isNotEmpty(competitions))
model.addAttribute("message", "无法删除,活动存在使用");
return "error";
productionTypeService.delete(id);
return "redirect:/admin/showProductionType";
//搜索竞赛分类信息
@RequestMapping(value = "selectProductionType", method = RequestMethod.POST)
private String selectProductionType(String findByName, Model model) throws Exception
List<ProductionType> list = productionTypeService.findByName(findByName);
model.addAttribute("productionTypeList", list);
return "admin/showProductionType";
// 竞赛作品信息显示
@RequestMapping("/showProduction")
public String showProduction(Model model, Integer page) throws Exception
List<Production> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(productionService.getCountProduction());
if (page == null || page == 0)
pagingVO.setToPageNo(1);
list = productionService.findByPaging(1,"","");
else
pagingVO.setToPageNo(page);
list = productionService.findByPaging(page,"","");
model.addAttribute("productionList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showProduction";
//搜索竞赛作品信息
@RequestMapping(value = "selectProduction", method = RequestMethod.POST)
private String selectProduction(String findByName, Model model) throws Exception
List<Production> list = productionService.findByName(findByName,null,null);
model.addAttribute("productionList", list);
return "admin/showProduction";
// 修改竞赛作品信息页面显示
@RequestMapping(value = "/editProduction", method = RequestMethod.GET)
public String editProductionUI(Integer id, Model model) throws Exception
if (id == null)
return "redirect:/admin/showProduction";
Production production = productionService.queryById(id);
if (production == null)
throw new CustomException("未找到该竞赛作品");
Integer competitionid = production.getCompetitionid();
Competition competition = competitionService.queryById(competitionid);
if (competition == null)
model.addAttribute("message", "作品参与的竞赛活动不存在!");
return "error";
if (competition.getStatus() != 1)
model.addAttribute("message", "竞赛已经进入打分阶段无法进行作品修改!");
return "error";
model.addAttribute("production", production);
return "admin/editProduction";
// 修改竞赛作品信息页面处理
@RequestMapping(value = "/editProduction", method = RequestMethod.POST)
public String editProduction(@RequestParam("myFile") MultipartFile file, Production production, Model model) throws Exception
//获取文件名称
String fileName = file.getOriginalFilename();
if (StrUtil.isNotBlank(fileName))
// 以下为创建新存储的文件路径
String upload = "D:/upload";
String localPath = upload;
// 没有D://test/upimage文件夹的话就新疆文件夹
File upimagesFile = new File(localPath);
if (!upimagesFile.exists())
upimagesFile.mkdirs();
String localFilePath = localPath + "/" + fileName;
//创建图片文件
File picFile = new File(localFilePath);
if (!picFile.exists())
picFile.createNewFile();
//保存文件
file.transferTo(picFile);
production.setMaterial(fileName);
else
Production production1 = productionService.queryById(production.getProductionid());
if (ObjectUtil.isNotNull(production1))
if (StrUtil.isNotBlank(production1.getMaterial()))
production.setMaterial(production1.getMaterial());
Integer competitionid = production.getCompetitionid();
Competition competition = competitionService.queryById(competitionid);
if (competition == null)
model.addAttribute("message", "作品参与的竞赛活动不存在!");
return "error";
if (competition.getStatus() != 1)
model.addAttribute("message", "竞赛已经进入打分阶段无法进行作品修改!");
return "error";
production.setCreatetime(new Date());
productionService.update(production);
//重定向
return "redirect:/admin/showProduction";
// 删除竞赛作品
@RequestMapping("/removeProduction")
public String removeProduction(Integer id, Model model) throws Exception
if (id == null)
return "showProduction";
Production production = productionService.queryById(id);
if (production == null)
model.addAttribute("message", "删除的作品不存在");
return "error";
productionService.delete(id);
return "redirect:/admin/showProduction";
// 去评价
@RequestMapping(value = "/evaluationProduction", method = RequestMethod.GET)
public String evaluationProductionUI(Integer id, Model model) throws Exception
if (id == null)
return "redirect:/admin/showProduction";
Production production = productionService.queryById(id);
if (production == null)
throw new CustomException("未找到该竞赛作品");
Integer competitionid = production.getCompetitionid();
Competition competition = competitionService.queryById(competitionid);
if (ObjectUtil.isNull(competition))
model.addAttribute("message", "竞赛活动不存在!");
return "error";
if (competition.getStatus() != 2)
model.addAttribute("message", "竞赛活动当前状态不可评价!");
return "error";
model.addAttribute("production", production);
return "admin/evaluationProduction";
// 评价作品
@RequestMapping(value = "/evaluationProduction", method = RequestMethod.POST)
public String evaluationProduction(Production production, Model model) throws Exception
if (production.getScore() == null)
model.addAttribute("message", "分数不能为空");
return "error";
if (StrUtil.isBlank(production.getRemark()))
model.addAttribute("message", "评语不能为空");
return "error";
String username = (String) SecurityUtils.getSubject().getPrincipal();
Integer productionid = production.getProductionid();
Integer score = production.getScore();
if ( productionid != null && score != null)
Production production1 = productionService.queryById(productionid);
if (ObjectUtil.isNotNull(production1))
production1.setScore(score);
production1.setRemark(production.getRemark());
TeacherCustom teacherCustom = teacherService.findById(Integer.valueOf(username));
if (ObjectUtil.isNotNull(teacherCustom))
production1.setJuryid(teacherCustom.getUserid());
production1.setJuryname(teacherCustom.getUsername());
productionService.update(production1);
//重定向
return "redirect:/admin/showProduction";
// 竞赛信息显示
@RequestMapping("/showCompetition")
public String showCompetition(Model model, Integer page) throws Exception
List<Competition> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(competitionService.getCountCompetition());
if (page == null || page == 0)
pagingVO.setToPageNo(1);
list = competitionService.findByPaging(1);
else
pagingVO.setToPageNo(page);
list = competitionService.findByPaging(page);
model.addAttribute("competitionList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showCompetition";
//添加竞赛
@RequestMapping(value = "/addCompetition", method = RequestMethod.GET)
public String addCompetitionUI(Model model) throws Exception
List<Integer> roleIds = new ArrayList();
roleIds.add(1);
roleIds.add(3);
List<Userlogin> userList = userloginService.findByRoleId(roleIds);
List<ProductionType> productionTypeList = productionTypeService.list("1");
model.addAttribute("userList", userList);
model.addAttribute("productionTypeList", productionTypeList);
return "admin/addCompetition";
// 添加竞赛信息处理
@RequestMapping(value = "/addCompetition", method = RequestMethod.POST)
public String addCompetition(Competition competition, Model model) throws Exception
String competitionname = competition.getCompetitionname();
if (StrUtil.isBlank(competitionname))
model.addAttribute("message", "竞赛名称不能为空!");
return "error";
List<Competition> list = competitionService.findByName(competitionname);
if (CollectionUtil.isNotEmpty(list))
model.addAttribute("message", "竞赛名称已存在!");
return "error";
Date endtime = competition.getEndtime();
if (endtime == null)
model.addAttribute("message", "报名截止时间不能为空!");
return "error";
Date publishtime = competition.getPublishtime();
if (publishtime == null)
model.addAttribute("message", "成绩公布时间不能为空!");
return "error";
String stipulation = competition.getStipulation();
if (StrUtil.isBlank(stipulation))
model.addAttribute("message", "要求不能为空!");
return "error";
String content = competition.getContent();
if (StrUtil.isBlank(content))
model.addAttribute("message", "内容不能为空!");
return "error";
String organizers = competition.getOrganizers();
if (StrUtil.isBlank(organizers))
model.addAttribute("message", "举办方不能为空!");
return "error";
competition.setStarttime(null);
competition.setStatus(0);
competition.setOrganizersid(0);
competitionService.save(competition);
//重定向
return "redirect:/admin/showCompetition";
// 修改竞赛活动信息页面显示
@RequestMapping(value = "/editCompetition", method = RequestMethod.GET)
public String editCompetitionUI(Integer id, Model model) throws Exception
List<Integer> roleIds = new ArrayList();
if (id == null)
return "redirect:/admin/showCompetition";
Competition competition = competitionService.queryById(id);
roleIds.add(1);
roleIds.add(3);
List<Userlogin> userList = userloginService.findByRoleId(roleIds);
List<ProductionType> productionTypeList = productionTypeService.list();
if (competition == null)
model.addAttribute("message", "竞赛活动不存在!");
return "error";
if (competition.getStatus() != 0)
model.addAttribute("message", "活动仅在筹备状态才可修改!");
return "error";
model.addAttribute("competition", competition);
model.addAttribute("userList", userList);
model.addAttribute("productionTypeList", productionTypeList);
return "admin/editCompetition";
// 修改竞赛作品信息页面处理
@RequestMapping(value = "/editCompetition", method = RequestMethod.POST)
public String editCompetition(Competition competition, Model model) throws Exception
String competitionname = competition.getCompetitionname();
if (StrUtil.isBlank(competitionname))
model.addAttribute("message", "竞赛名称不能为空!");
return "error";
List<Competition> list = competitionService.findByName(competitionname);
if (CollectionUtil.isNotEmpty(list))
Competition competition1 = list.get(0);
if (competition1.getCompetitionid() != competition.getCompetitionid())
model.addAttribute("message", "竞赛名称已存在!");
return "error";
Date publishtime = competition.getPublishtime();
if (publishtime == null)
model.addAttribute("message", "成绩公布时间不能为空!");
return "error";
Date endtime = competition.getEndtime();
if (endtime == null)
model.addAttribute("message", "报名截止时间不能为空!");
return "error";
String stipulation = competition.getStipulation();
if (StrUtil.isBlank(stipulation))
model.addAttribute("message", "要求不能为空!");
return "error";
String content = competition.getContent();
if (StrUtil.isBlank(content))
model.addAttribute("message", "内容不能为空!");
return "error";
String organizers = competition.getOrganizers();
if (StrUtil.isBlank(organizers))
model.addAttribute("message", "举办方不能为空!");
return "error";
if (competition.getJuryids() != null)
Userlogin userlogin = userloginService.queryById(Integer.valueOf(competition.getJuryids()));
if (ObjectUtil.isNotNull(userlogin))
competition.setJuryidnames(userlogin.getUsername());
if (competition.getProductiontypeid() != null)
ProductionType productionType = productionTypeService.queryById(Integer.valueOf(competition.getProductiontypeid()));
if (ObjectUtil.isNotNull(productionType))
competition.setProductiontypename(productionType.getProductiontypename());
competitionService.update(competition);
//重定向
return "redirect:/admin/showCompetition";
// 手动开启报名
@RequestMapping(value = "/applyCompetition", method = RequestMethod.GET)
public String editCompetition(Integer id, Model model) throws Exception
Competition competition = competitionService.queryById(id);
if (ObjectUtil.isNull(competition))
model.addAttribute("message", "竞赛活动不存在!");
return "error";
competition.setStarttime(new Date());
competition.setStatus(1);
competitionService.update(competition);
//重定向
return "redirect:/admin/showCompetition";
// 手动报名截止
@RequestMapping(value = "/deadlineCompetition", method = RequestMethod.GET)
public String deadlineCompetition(Integer id, Model model) throws Exception
Competition competition = competitionService.queryById(id);
if (ObjectUtil.isNull(competition))
model.addAttribute("message", "竞赛活动不存在!");
return "error";
if (competition.getStatus() != 1)
model.addAttribute("message", "当前活动状态异常!");
return "error";
competition.setStatus(2);
competitionService.update(competition);
//重定向
return "redirect:/admin/showCompetition";
// 手动结束活动
@RequestMapping(value = "/endCompetition", method = RequestMethod.GET)
public String endCompetition(Integer id, Model model) throws Exception
Competition competition = competitionService.queryById(id);
if (ObjectUtil.isNull(competition))
model.addAttribute("message", "竞赛活动不存在!");
return "error";
if (competition.getStatus() != 2)
model.addAttribute("message", "当前活动状态异常!");
return "error";
competition.setStatus(3);
competitionService.update(competition);
//重定向
return "redirect:/admin/showCompetition";
// 删除竞赛活动
@RequestMapping("/removeCompetition")
public String removeCompetition(Integer id, Model model) throws Exception
if (id == null)
return "showCompetition";
Competition competition = competitionService.queryById(id);
if (competition == null)
model.addAttribute("message", "删除的活动不存在");
return "error";
if (competition.getStatus() != 0)
model.addAttribute("message", "仅可删除筹办中的活动");
return "error";
competitionService.delete(id);
return "redirect:/admin/showCompetition";
//搜索竞赛信息
@RequestMapping(value = "selectCompetition", method = RequestMethod.POST)
private String selectCompetition(String findByName, Model model) throws Exception
List<Competition> list = competitionService.findByName(findByName);
model.addAttribute("competitionList", list);
return "admin/showCompetition";
//添加课程
@RequestMapping(value = "/addCourse", method = RequestMethod.GET)
public String addCourseUI(Model model) throws Exception
List<TeacherCustom> list = teacherService.findAll();
List<College> collegeList = collegeService.finAll();
model.addAttribute("collegeList", collegeList);
model.addAttribute("teacherList", list);
return "admin/addCourse";
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<其他操作>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
// 普通用户账号密码重置
@RequestMapping("/userPasswordRest")
public String userPasswordRestUI() throws Exception
return "admin/userPasswordRest";
// 普通用户账号密码重置处理
@RequestMapping(value = "/userPasswordRest", method = RequestMethod.POST)
public String userPasswordRest(Userlogin userlogin) throws Exception
Userlogin u = userloginService.findByName(userlogin.getUsername());
if (u != null)
if (u.getRole() == 0)
throw new CustomException("该账户为管理员账户,没法修改");
u.setPassword(userlogin.getPassword());
userloginService.updateByName(userlogin.getUsername(), u);
else
throw new CustomException("没找到该用户");
return "admin/userPasswordRest";
// 本账户密码重置
@RequestMapping("/passwordRest")
public String passwordRestUI() throws Exception
return "admin/passwordRest";
@RequestMapping(value="/download",method=RequestMethod.GET) //匹配的是href中的download请求
public ResponseEntity<byte[]> download(@RequestParam("filename") String filename,
Model model) throws IOException
String downloadFilePath="D:\\\\upload";//从我们的上传文件夹中去取
File file = new File(downloadFilePath+File.separator+filename);//新建一个文件
HttpHeaders headers = new HttpHeaders();//http头信息
String downloadFileName = new String(filename.getBytes("UTF-8"),"iso-8859-1");//设置编码
headers.setContentDispositionFormData("attachment", downloadFileName);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//MediaType:互联网媒介类型 contentType:具体请求中的媒体类型信息
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
//==============院系操作==================
// 院系页面显示
@RequestMapping("/showCollege")
public String showCollege(Model model, Integer page) throws Exception
List<CollegeCustom> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(collegeService.getCountCollege());
if (page == null || page == 0)
pagingVO.setToPageNo(1);
list = collegeService.findByPaging(1);
else
pagingVO.setToPageNo(page);
list = collegeService.findByPaging(page);
model.addAttribute("collegeList", list);
model.addAttribute("pagingVO", pagingVO);
return "admin/showCollege";
/**
* 添加院系信息页面显示
*/
@RequestMapping(value = "/addCollege", method = RequestMethod.GET)
public String addCollegeUI(Model model) throws Exception
return "admin/addCollege";
/**
* 添加院系信息操作
*/
@RequestMapping(value = "/addCollege", method = RequestMethod.POST)
public String addCollege(College college, Model model) throws Exception
if (StrUtil.isBlank(college.getCollegename()))
model.addAttribute("message", "院系名不能为空");
return "error";
CollegeCustom collegeCustom = new CollegeCustom();
collegeCustom.setCollegename(college.getCollegename());
collegeService.save(collegeCustom);
//重定向
return "redirect:/admin/showCollege";
/**
* 删除院系
* @param id
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/removeCollege")
public String removeCollege(Integer id, Model model) throws Exception
if (id == null)
return "showCollege";
College college = collegeService.findById(id);
if (college == null)
model.addAttribute("message", "删除的院系不存在");
return "error";
collegeService.removeById(id);
return "redirect:/admin/showCollege";
/**
*
* 修改院系信息页面显示
* @param id
* @param model
* @return
* @throws Exception
*/
@RequestMapping(value = "/editCollege", method = RequestMethod.GET)
public String editCollegeUI(Integer id, Model model) throws Exception
if (id == null)
return "redirect:/admin/showCollege";
CollegeCustom college = collegeService.findById(id);
if (college == null)
throw new CustomException("未找到该院系");
model.addAttribute("college", college);
return "admin/editCollege";
/**
* 修改院系信息页面处理
* @param college
* @param model
* @return
* @throws Exception
*/
@RequestMapping(value = "/editCollege", method = RequestMethod.POST)
public String editCollege(College college, Model model) throws Exception
if (college.getCollegeid() == null)
model.addAttribute("message", "编号不能为空");
return "error";
if (StrUtil.isBlank(college.getCollegename()))
model.addAttribute("message", "院系名字不能为空");
return "error";
CollegeCustom collegeCustom = new CollegeCustom();
BeanUtils.copyProperties(college, collegeCustom);
collegeService.updateById(college.getCollegeid(), collegeCustom);
//重定向
return "redirect:/admin/showCollege";
//搜索竞赛信息
@RequestMapping(value = "selectCollege", method = RequestMethod.POST)
private String selectCollege(String findByName, Model model) throws Exception
List<CollegeCustom> list = collegeService.findByName(findByName);
model.addAttribute("collegeList", list);
return "admin/showCollege";
以上是关于基于SSM实现学生竞赛管理系统的主要内容,如果未能解决你的问题,请参考以下文章
Java+JSP+MySQL基于SSM的学生宿舍管理系统的设计与实现
基于javaweb基于ssm框架学生信息管理(选课)系统设计与实现(项目源码)