作者主页:Java毕设网
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
一、相关文档
二、项目介绍
该项目分为学生、教师两个角色,主要功能如下:
1. 学生模块
1) 我的课程:学生可在此页面自由选课
2) 我的作业:可查看选择的课程已发布的作业及完成情况,并可选择完成作业或查看详情
2. 教师模块
1) 学生管理:
I. 查询学生:可根据学生信息搜索学生,可进行修改删除操作,可进行全选批量删除和导出excel表格,可根据查询到的数据进行分页,输入页码进行跳转操作
II. 添加学生:可进行单个添加学生或excel表格导入学生
2) 教师管理:
I. 查询教师:可根据教师信息搜索教师,可进行修改删除操作,可进行全选批量删除和导出excel表格,可根据查询到的数据进行分页,输入页码进行跳转操作
II. 添加教师:可进行单个添加学生或excel表格导入教师
3) 班级管理:
I. 查询班级:可查看所有班级,进行删除修改等操作
II. 添加班级:可进行添加班级操作
4) 课程管理:
I. 查询课程:可查看所有课程,进行修改删除操作
II. 添加班级:可进行添加课程操作
5) 作业管理:
I. 查看作业完成情况:可查看每门科目项目学生作业的完成情况,可根据起止时间和课程名称进行搜索。
II. 添加作业:选择一门课程搜索题库,在题库中选择题目后进行作业发布操作
III. 编辑题库:可对题库进行增删改操作
三、环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7、8.0等版本均可;
5.是否Maven项目:是
四、技术栈
1. 后端:SpringBoot+Mybatis+Thymeleaf模板引擎
2. 前端:HTML+CSS+JavaScript+BootStrap+jQuery
五、使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
六、运行截图
七、相关代码
学生管理控制器
package com.hbzy.homework.controller.student;
import com.hbzy.homework.entity.Course;
import com.hbzy.homework.entity.Student;
import com.hbzy.homework.entity.StudentCourse;
import com.hbzy.homework.service.SelectCourseService;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("student")
public class SelectCourseController {
@Autowired
SelectCourseService selectCourseService;
@RequestMapping(value = "select_course",method = RequestMethod.GET)
public String toSelectCourse(Model model, HttpSession session){
Integer id=(Integer) session.getAttribute("sid");
List<StudentCourse> studentCourses =selectCourseService.selectCourseByStudent(id);
List<Course> courses=selectCourseService.selectAllCourse();
Map<Integer,String> courseMap=new HashMap<Integer,String>();
for (Course cs:courses
) {
courseMap.put(cs.getId(),cs.getCourseName());
}
List<Course> courses1=new ArrayList<>();
for (StudentCourse sc:studentCourses
) {
Course c=new Course();
c.setId(sc.getCourseId());
c.setCourseName(courseMap.get(sc.getCourseId()));
courses1.add(c);
}
Course rmcs=new Course();
for (int i=0;i<studentCourses.size();i++){
rmcs.setId(studentCourses.get(i).getCourseId());
rmcs.setCourseName(courseMap.get(studentCourses.get(i).getCourseId()));
courses.remove(rmcs);
}
model.addAttribute("courses",courses1);
model.addAttribute("allcourse",courses);
return "/student/select_course";
}
@RequestMapping(value = "add_student_course",method = RequestMethod.GET)
public String addStuCourse(Integer courseId,HttpSession session){
StudentCourse studentCourse=new StudentCourse();
Integer id=(Integer) session.getAttribute("sid");
studentCourse.setCourseId(courseId);
studentCourse.setStudentId(id);
selectCourseService.insertStudentCourse(studentCourse);
return "redirect:/student/select_course";
}
@RequestMapping(value = "delete_student_course",method = RequestMethod.GET)
public String deleteStudentCourse(Integer courseId,HttpSession session){
Integer id=(Integer) session.getAttribute("sid");
selectCourseService.deleteStudentCourse(id,courseId);
return "redirect:/student/select_course";
}
}
教师管理控制器
package com.hbzy.homework.controller.teacher;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hbzy.homework.entity.*;
import com.hbzy.homework.service.TeacherManagementService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
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 org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
@Controller
@RequestMapping("teacher")
public class TeacherManagementController {
@Autowired
TeacherManagementService teacherManagementService;
@RequestMapping(value = "add_teacher",method = RequestMethod.GET)
public String addTeacher(Model model){
List<Course> courses=teacherManagementService.selectAllCourse();
model.addAttribute("courses",courses);
return "teacher/add_teacher";
}
@RequestMapping(value = "show_teacher_bypage",method = RequestMethod.GET)
public String showTeacherByPage(Model model, Page page, @Nullable Teacher teacher, HttpSession session){
if (page.getPageNum()==0)
page.setPageNum(1);
Teacher teacher1=new Teacher();
if (session.getAttribute("teacher")!=null) {
teacher1 = (Teacher) session.getAttribute("teacher");
}
if (teacher.getId()==null&&teacher.getTeacherName()==null&&teacher.getCourseId()==null&&teacher1.getId()==null&&teacher1.getTeacherName()==null&&teacher1.getCourseId()==null){
PageHelper.startPage(page.getPageNum(),10);
List<Teacher> teachers=teacherManagementService.selectAllTeacher();
List<Course> courses=teacherManagementService.selectAllCourse();
PageInfo pageInfo=new PageInfo(teachers);
model.addAttribute("teachers",teachers);
model.addAttribute("courses",courses);
model.addAttribute("pageInfo",pageInfo);
return "teacher/show_teacher";
}
if(session.getAttribute("teacher")==null)
session.setAttribute("teacher",teacher);
if (teacher.getId()!=null||teacher.getTeacherName()!=null||teacher.getCourseId()!=null&&session.getAttribute("teacher").equals(teacher)){
session.removeAttribute("teacher");
session.setAttribute("teacher",teacher);}
PageHelper.startPage(page.getPageNum(),10);
List<Teacher> teachers=teacherManagementService.selectTeacherByAny((Teacher)session.getAttribute("teacher"));
List<Course> courses=teacherManagementService.selectAllCourse();
PageInfo pageInfo=new PageInfo(teachers);
model.addAttribute("teachers",teachers);
model.addAttribute("courses",courses);
model.addAttribute("pageInfo",pageInfo);
return "teacher/show_teacher";
}
@RequestMapping(value = "t_clean_select",method = RequestMethod.GET)
public String cleanSelect(HttpSession session){
if (session.getAttribute("teacher")!=null)
session.removeAttribute("teacher");
return "redirect:/teacher/show_teacher_bypage";
}
@RequestMapping(value = "delete_teacher/{id}/{pageNum}",method = RequestMethod.GET)
public String deleteTeacher(@PathVariable(name = "id")int id,@PathVariable(name = "pageNum")int pageNum, RedirectAttributes model){
int result=teacherManagementService.deleteTeacher(id);
if (result == 0){
model.addAttribute("msg","删除失败");
return "redirect:/teacher/show_teacher_bypage"+"?pageNum="+pageNum;
}
model.addAttribute("msg","删除成功");
return "redirect:/teacher/show_teacher_bypage"+"?pageNum="+pageNum;
}
@RequestMapping(value = "delete_teacher",method = RequestMethod.POST)
public String deleteAllTeacher(HttpServletRequest request, HttpServletResponse response){
String[] check = request.getParameterValues("check");
for (String s:check
) {
int id =Integer.parseInt(s);
teacherManagementService.deleteTeacher(id);
}
return "redirect:/teacher/show_teacher_bypage";
}
@RequestMapping(value = "add_teacher",method = RequestMethod.POST)
public String addTeacher(Teacher teacher,Model model){
if (teacherManagementService.selectTeacherByLoginName(teacher.getLoginName())!=null){
model.addAttribute("msg","添加失败,用户名已存在");
return "/teacher/add_teacher";}
int result=teacherManagementService.insertTeacher(teacher);
List<Course> courses=teacherManagementService.selectAllCourse();
model.addAttribute("courses",courses);
if (result==0){
model.addAttribute("msg","添加失败");
return "teacher/add_teacher";
}
model.addAttribute("msg","添加成功");
return "teacher/add_teacher";
}
@RequestMapping(value = "t_export_excel",method = RequestMethod.GET)
public String exportExcel(HttpServletResponse response,HttpSession session) throws IOException {
String fileName="教师信息";
HSSFWorkbook hssfWorkbook=teacherManagementService.exprotExcel((Teacher)session .getAttribute("teacher"));
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName );
OutputStream out=response.getOutputStream();
hssfWorkbook.write(out);
return null;
}
@RequestMapping(value = "t_export_excel_check",method = RequestMethod.GET)
public String getCheck(HttpServletRequest request){
String [] check = request.getParameterValues("check");
request.getSession().setAttribute("check",check);
return "redirect:/teacher/show_teacher_bypage";
}
@RequestMapping(value = "t_export_excel2",method = RequestMethod.GET)
public String exportExcelForSelect(HttpServletResponse response,HttpSession session,HttpServletRequest request) throws IOException {
if(session.getAttribute("check")==null){
return "redirect:/teacher/show_teacher_bypage";
}
String[] check = (String[]) session.getAttribute("check");
request.getSession().removeAttribute("check");
String fileName="教师信息";
HSSFWorkbook hssfWorkbook=teacherManagementService.exprotExcelForSelect(check);
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName );
OutputStream out=response.getOutputStream();
hssfWorkbook.write(out);
return null;
}
@RequestMapping(value = "upload_teacher",method = RequestMethod.POST,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String uploadTeacher(@RequestParam("teacherExcel") MultipartFile teacherExcel, Model model, Integer courseId)throws IOException {
InputStream inputStream = teacherExcel.getInputStream();
FileInputStream fileInputStream=(FileInputStream) inputStream;
String fileName=teacherExcel.getOriginalFilename().toLowerCase();
if (fileName.endsWith(".xls")||fileName.endsWith(".xlsx")){
String msgup=teacherManagementService.uploadAddTeacher(fileInputStream,fileName,courseId);
model.addAttribute("msgup",msgup);
return "teacher/add_teacher";
}else {
model.addAttribute("msgup","添加失败,请选择正确的文件类型");
return "teacher/add_teacher";
}
}
@RequestMapping(value = "update_teacher/{id}",method = RequestMethod.GET)
public String updateTeacher(@PathVariable(name = "id")int id, Model model){
List<Course> courses=teacherManagementService.selectAllCourse();
model.addAttribute("courses",courses);
model.addAttribute("teacher",teacherManagementService.selectTeacherById(id));
return "teacher/update_teacher";
}
@RequestMapping(value = "update_teacher",method = RequestMethod.POST)
public String updateTeacher(Teacher teacher, Model model){
teacherManagementService.updateTeacher(teacher);
return "redirect:/teacher/show_teacher_bypage";
}
}