文章目錄
- 學生選課成績管理系統
- 一、項目演示
- 二、項目介紹
- 三、8500字項目文檔
- 四、部分功能截圖
- 五、部分代碼展示
- 六、底部獲取項目源碼帶8500字文檔(9.9¥帶走)
學生選課成績管理系統
一、項目演示
選課成績管理系統
二、項目介紹
語言: Java 數據庫:MySQL
技術棧 : Spring 、Spring MVC 、Mybatis、jsp
系統角色:管理員、教師、用戶
1、管理員:登錄、課程管理(搜索課程、添加課程、修改課程、刪除課程)、學生管理(搜索學生、添加學生、修改學生、刪除學生)、教師管理(搜索教師、添加教師、修改教師、刪除教師)、賬號密碼重置、修改密碼
2、教師:登錄、我的課程(搜索課程、成績評分)、修改密碼
3、學生:所有課程、已選課程、已修課程、修改密碼
三、8500字項目文檔
四、部分功能截圖
五、部分代碼展示
package com.system.controller;import com.system.exception.CustomException;
import com.system.po.*;
import com.system.service.*;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
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.annotation.Resource;
import java.util.List;@Controller
@RequestMapping("/admin")
public class AdminController {@Resource(name = "studentServiceImpl")private StudentService studentService;@Resource(name = "teacherServiceImpl")private TeacherService teacherService;@Resource(name = "courseServiceImpl")private CourseService courseService;@Resource(name = "collegeServiceImpl")private CollegeService collegeService;@Resource(name = "userloginServiceImpl")private UserloginService userloginService;/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<學生操作>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/// 學生信息顯示@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 {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) throws Exception {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 {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) throws Exception {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("/showCourse")public String showCourse(Model model, Integer page) throws Exception {List<CourseCustom> list = null;//頁碼對象PagingVO pagingVO = new PagingVO();//設置總頁數pagingVO.setTotalCount(courseService.getCountCouse());if (page == null || page == 0) {pagingVO.setToPageNo(1);list = courseService.findByPaging(1);} else {pagingVO.setToPageNo(page);list = courseService.findByPaging(page);}model.addAttribute("courseList", list);model.addAttribute("pagingVO", pagingVO);return "admin/showCourse";}//添加課程@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(value = "/addCourse", method = {RequestMethod.POST})public String addCourse(CourseCustom courseCustom, Model model) throws Exception {Boolean result = courseService.save(courseCustom);if (!result) {model.addAttribute("message", "課程號重復");return "error";}//重定向return "redirect:/admin/showCourse";}// 修改教師信息頁面顯示@RequestMapping(value = "/editCourse", method = {RequestMethod.GET})public String editCourseUI(Integer id, Model model) throws Exception {if (id == null) {return "redirect:/admin/showCourse";}CourseCustom courseCustom = courseService.findById(id);if (courseCustom == null) {throw new CustomException("未找到該課程");}List<TeacherCustom> list = teacherService.findAll();List<College> collegeList = collegeService.finAll();model.addAttribute("teacherList", list);model.addAttribute("collegeList", collegeList);model.addAttribute("course", courseCustom);return "admin/editCourse";}// 修改教師信息頁面處理@RequestMapping(value = "/editCourse", method = {RequestMethod.POST})public String editCourse(CourseCustom courseCustom) throws Exception {courseService.upadteById(courseCustom.getCourseid(), courseCustom);//重定向return "redirect:/admin/showCourse";}// 刪除課程信息@RequestMapping("/removeCourse")public String removeCourse(Integer id) throws Exception {if (id == null) {//加入沒有帶教師id就進來的話就返回教師顯示頁面return "admin/showCourse";}courseService.removeById(id);return "redirect:/admin/showCourse";}//搜索課程@RequestMapping(value = "selectCourse", method = {RequestMethod.POST})private String selectCourse(String findByName, Model model) throws Exception {List<CourseCustom> list = courseService.findByName(findByName);model.addAttribute("courseList", list);return "admin/showCourse";}/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<其他操作>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/// 普通用戶賬號密碼重置@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";}}
package com.system.controller;import com.system.exception.CustomException;
import com.system.po.*;
import com.system.service.CourseService;
import com.system.service.SelectedCourseService;
import com.system.service.StudentService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;import javax.annotation.Resource;
import java.util.List;/*** Created by Jacey on 2017/7/5.*/
@Controller
@RequestMapping(value = "/student")
public class StudentController {@Resource(name = "courseServiceImpl")private CourseService courseService;@Resource(name = "studentServiceImpl")private StudentService studentService;@Resource(name = "selectedCourseServiceImpl")private SelectedCourseService selectedCourseService;@RequestMapping(value = "/showCourse")public String stuCourseShow(Model model, Integer page) throws Exception {List<CourseCustom> list = null;//頁碼對象PagingVO pagingVO = new PagingVO();//設置總頁數pagingVO.setTotalCount(courseService.getCountCouse());if (page == null || page == 0) {pagingVO.setToPageNo(1);list = courseService.findByPaging(1);} else {pagingVO.setToPageNo(page);list = courseService.findByPaging(page);}model.addAttribute("courseList", list);model.addAttribute("pagingVO", pagingVO);return "student/showCourse";}// 選課操作@RequestMapping(value = "/stuSelectedCourse")public String stuSelectedCourse(int id) throws Exception {//獲取當前用戶名Subject subject = SecurityUtils.getSubject();String username = (String) subject.getPrincipal();SelectedCourseCustom selectedCourseCustom = new SelectedCourseCustom();selectedCourseCustom.setCourseid(id);selectedCourseCustom.setStudentid(Integer.parseInt(username));SelectedCourseCustom s = selectedCourseService.findOne(selectedCourseCustom);if (s == null) {selectedCourseService.save(selectedCourseCustom);} else {throw new CustomException("該門課程你已經選了,不能再選");}return "redirect:/student/selectedCourse";}// 退課操作@RequestMapping(value = "/outCourse")public String outCourse(int id) throws Exception {Subject subject = SecurityUtils.getSubject();String username = (String) subject.getPrincipal();SelectedCourseCustom selectedCourseCustom = new SelectedCourseCustom();selectedCourseCustom.setCourseid(id);selectedCourseCustom.setStudentid(Integer.parseInt(username));selectedCourseService.remove(selectedCourseCustom);return "redirect:/student/selectedCourse";}// 已選課程@RequestMapping(value = "/selectedCourse")public String selectedCourse(Model model) throws Exception {//獲取當前用戶名Subject subject = SecurityUtils.getSubject();StudentCustom studentCustom = studentService.findStudentAndSelectCourseListByName((String) subject.getPrincipal());List<SelectedCourseCustom> list = studentCustom.getSelectedCourseList();model.addAttribute("selectedCourseList", list);return "student/selectCourse";}// 已修課程@RequestMapping(value = "/overCourse")public String overCourse(Model model) throws Exception {//獲取當前用戶名Subject subject = SecurityUtils.getSubject();StudentCustom studentCustom = studentService.findStudentAndSelectCourseListByName((String) subject.getPrincipal());if (studentCustom==null){throw new CustomException("你還沒有修完任何一門課,請先選課學習吧!");}List<SelectedCourseCustom> list = studentCustom.getSelectedCourseList();model.addAttribute("selectedCourseList", list);return "student/overCourse";}//修改密碼@RequestMapping(value = "/passwordRest")public String passwordRest() throws Exception {return "student/passwordRest";}}
package com.system.service.impl;import com.system.exception.CustomException;
import com.system.mapper.CollegeMapper;
import com.system.mapper.CourseMapper;
import com.system.mapper.TeacherMapper;
import com.system.mapper.TeacherMapperCustom;
import com.system.po.*;
import com.system.service.TeacherService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.ArrayList;
import java.util.List;/*** Created by Jacey on 2017/6/29.*/
@Service
public class TeacherServiceImpl implements TeacherService {@Autowiredprivate TeacherMapper teacherMapper;@Autowiredprivate TeacherMapperCustom teacherMapperCustom;@Autowiredprivate CollegeMapper collegeMapper;@Autowiredprivate CourseMapper courseMapper;public void updateById(Integer id, TeacherCustom teacherCustom) throws Exception {teacherMapper.updateByPrimaryKey(teacherCustom);}public void removeById(Integer id) throws Exception {CourseExample courseExample = new CourseExample();CourseExample.Criteria criteria = courseExample.createCriteria();criteria.andTeacheridEqualTo(id);List<Course> list = courseMapper.selectByExample(courseExample);if (list.size() != 0) {throw new CustomException("請先刪除該名老師所教授的課程");}teacherMapper.deleteByPrimaryKey(id);}public List<TeacherCustom> findByPaging(Integer toPageNo) throws Exception {PagingVO pagingVO = new PagingVO();pagingVO.setToPageNo(toPageNo);List<TeacherCustom> list = teacherMapperCustom.findByPaging(pagingVO);return list;}public Boolean save(TeacherCustom teacherCustom) throws Exception {Teacher tea = teacherMapper.selectByPrimaryKey(teacherCustom.getUserid());if (tea == null) {teacherMapper.insert(teacherCustom);return true;}return false;}public int getCountTeacher() throws Exception {//自定義查詢對象TeacherExample teacherExample = new TeacherExample();//通過criteria構造查詢條件TeacherExample.Criteria criteria = teacherExample.createCriteria();criteria.andUseridIsNotNull();return teacherMapper.countByExample(teacherExample);}public TeacherCustom findById(Integer id) throws Exception {Teacher teacher = teacherMapper.selectByPrimaryKey(id);TeacherCustom teacherCustom = null;if (teacher != null) {teacherCustom = new TeacherCustom();BeanUtils.copyProperties(teacher, teacherCustom);}return teacherCustom;}public List<TeacherCustom> findByName(String name) throws Exception {TeacherExample teacherExample = new TeacherExample();//自定義查詢條件TeacherExample.Criteria criteria = teacherExample.createCriteria();criteria.andUsernameLike("%" + name + "%");List<Teacher> list = teacherMapper.selectByExample(teacherExample);List<TeacherCustom> teacherCustomList = null;if (list != null) {teacherCustomList = new ArrayList<TeacherCustom>();for (Teacher t : list) {TeacherCustom teacherCustom = new TeacherCustom();//類拷貝BeanUtils.copyProperties(t, teacherCustom);//獲取課程名College college = collegeMapper.selectByPrimaryKey(t.getCollegeid());teacherCustom.setcollegeName(college.getCollegename());teacherCustomList.add(teacherCustom);}}return teacherCustomList;}public List<TeacherCustom> findAll() throws Exception {TeacherExample teacherExample = new TeacherExample();TeacherExample.Criteria criteria = teacherExample.createCriteria();criteria.andUsernameIsNotNull();List<Teacher> list = teacherMapper.selectByExample(teacherExample);List<TeacherCustom> teacherCustomsList = null;if (list != null) {teacherCustomsList = new ArrayList<TeacherCustom>();for (Teacher t: list) {TeacherCustom teacherCustom = new TeacherCustom();BeanUtils.copyProperties(t, teacherCustom);teacherCustomsList.add(teacherCustom);}}return teacherCustomsList;}
}
六、底部獲取項目源碼帶8500字文檔(9.9¥帶走)
有問題,或者需要協助調試運行項目的也可以