基于javaweb+mysql的ssm+maven网上选课系统(java+ssm+jsp+mysql+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven网上选课系统(java+ssm+jsp+mysql+maven)
一、项目简述
功能: 系统分为三个角色。最高权限管理员,学生,教师,包括 学生管理,教师管理,课程管理,选课,退课,成绩查 询。,教学课程,查看选课名单等等功能完全齐备。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + Bootstrap4+ css + JavaScript + JQuery + Ajax + particles.js+ maven等等。
if (serc.equals("all")) {
teacherList = teacherService.selectTeacherBySql(1,10);
pageIn(model, teacherList);
request.setAttribute("teacherList", teacherList);
return "admin/queryTeacher";
} else if (serc.equals("tid")) {
teacherList = teacherService.getByTeacherTid(1,10,condition);
pageIn(model, teacherList);
request.setAttribute("teacherList", teacherList);
System.out.println("tid");
return "admin/queryTeacher";
} else {
teacherList = teacherService.selectTeacherBySql(1,10);
pageIn(model, teacherList);
request.setAttribute("teacherList", teacherList);
return "admin/queryTeacher";
}
}
//删除教师
@RequestMapping(value = "/deleteTea/{tid}", method = RequestMethod.GET)
public String deleteTeacher(@PathVariable(value = "tid") String tid, Model model) {
if (teacherService.deleteTeacher(tid) != 0) {
System.out.println("success");
//------------------------代优化,现状:删除后需要手动刷新界面或者重新查询,不能实时刷新。---------------------------------------------------
return "success";
} else {
System.out.println("fail");
return "fail";
}
}
//查询全部学生方法
public void queryStu(HttpServletRequest request) {
List<Student> studentList = new ArrayList<Student>();
studentList = studentService.selectStudentBySql(1,10);
request.setAttribute("slist", studentList);
}
public void pageIn(Model model,List list) {
PageInfo page = new PageInfo(list, 5);
model.addAttribute("pageInfo", page);
}
// 查询
@RequestMapping(value = "/query/{pn}", method = RequestMethod.GET)
public String redirect(@RequestParam("serc") String serc, @RequestParam("condition") String condition,HttpServletRequest request,
@PathVariable(value = "pn") String pn,Model model) {
int no = Integer.parseInt(pn);
// System.out.println("-----"+no+"----");
List<Student> studentList = new ArrayList<Student>();
PageHelper.startPage(no, 5);
request.setAttribute("serc", serc);
request.setAttribute("condition", condition);
//查询全部
if (serc.equals("all")) {
System.out.println("------------------------------------------------------------------------------------------------");
// studentList = studentService.selectStudentBySql(1,10);
// //model.addAttribute("studentList", studentList);
// request.setAttribute("slist", studentList);
// System.out.println("00000"+request.getAttribute("slist"));
// System.out.println(studentList);
studentList = studentService.selectStudentBySql(1,10);
pageIn(model, studentList);
request.setAttribute("slist", studentList);
return "admin/queryStudent";
//根据学号查询
} else if (serc.equals("sid")) {
studentList = studentService.getByStudentSid(1,10,condition);
pageIn(model, studentList);
request.setAttribute("slist", studentList);
System.out.println("sid");
return "admin/queryStudent";
return "teacher/addCou";
}
@RequestMapping("/sercsc")
public String sercSC() {
return "teacher/serchSC";
}
/*
*
*/
@RequestMapping("/queryvita/{tid}")
public String queryVita(@PathVariable(value = "tid") String tid, Model model) {
Teacher teacher = new Teacher();
teacher = teacherService.getByTeaTid(tid);
model.addAttribute("tid", teacher.getTid());
model.addAttribute("tname", teacher.getTname());
model.addAttribute("tpassword", teacher.getTpassword());
model.addAttribute("tsex", teacher.getTsex());
model.addAttribute("introduction", teacher.getIntroduction());
System.out.println(teacher);
System.out.println(teacher.getTpassword());
return "teacher/queryVita";
}
public void pageIn(Model model, List list) {
PageInfo page = new PageInfo(list, 5);
model.addAttribute("pageInfo", page);
}
@RequestMapping("/managecou/{tid}/{pn}")
public String manageCou(@PathVariable(value = "tid") String tid, Model model, HttpSession httpSession,
@PathVariable(value = "pn") String pn) {
// Course course = new Course();
// CoursePlan coursePlan = new CoursePlan();
int no = Integer.parseInt(pn);
PageHelper.startPage(no, 5);
List<CoursePlan> coursePlanList = new ArrayList<CoursePlan>();
List<Course> couList = new ArrayList<Course>();
model.addAttribute("cid", cid);
return "student/noseling";
}
}
// 加入课程
@RequestMapping("/seling")
public String confirmSelect(@RequestParam("cid") String cid, @RequestParam("sid") String sid, Model model,
HttpSession httpSession, HttpServletRequest httpRequest) {
// 判断是否加入过此课程
if (selectCourseService.existCourse(cid, sid) != null) {
httpRequest.setAttribute("msg", "已经加入过该课程,不能重复加入!");
System.out.println("已经加入过该课程,不能重复加入!");
return "fail";
}
if (selectCourseService.selectCourse(cid, sid) != 0) {
System.out.println(cid);
System.out.println(sid);
return "success";
} else {
return "fail";
}
}
// 退出
@RequestMapping("/backseling/{cid}")
public ModelAndView backConfirmSelect(@PathVariable(value = "cid") String cid) {
return new ModelAndView(new RedirectView("/StudentInfo/StudentHandler/selqueryy/1"));
}
// 跳转页面
@RequestMapping("/selqueryy/{pn}")
public String selQueryy(HttpServletRequest request, @PathVariable(value = "pn") String pn, Model model) {
int no = Integer.parseInt(pn);
List<Course> courseList = new ArrayList<Course>();
PageHelper.startPage(no, 5);
courseList = courseService.selectCourseBySql(1, 10);
pageIn(model, courseList);
request.setAttribute("courseList", courseList);
return "student/selCourse";
}
// 学生查询本人选课
@RequestMapping(value = "/selcouresult/{sid}/{pn}", method = RequestMethod.GET)
public String selcouresult(@PathVariable("sid") String sid, StuSelectResult ssr, HttpServletRequest request,
@PathVariable(value = "pn") String pn, Model model) {
/**
* @ProjectName: StudentInfo
* @Package: net.fuzui.StudentInfo.handler
* @ClassName: AdminHandler
* @Description: admin的handler层(servlet)
* @UpdateUser: 王泽
* @UpdateRemark: 新建
* @Version: 1.0
*/
@Controller
@RequestMapping("/LoginHandler")
public class LoginHandler {
@Autowired
AdminService adminServiceImpl;
@Autowired
StudentService studentService;
@Autowired
TeacherService teacherService;
//管理员登录
@RequestMapping("/adminlogin")
public String loginStudent(@RequestParam("aname") String aname, @RequestParam("apassword") String apassword,
Model model, HttpSession httpSession) {
String n = null;
n = adminServiceImpl.queryByNamePwd(aname,apassword);
if (n != null && !"".equals(n)) {
httpSession.setAttribute("aname", aname);
return "admin/adminFace";
} else {
return "fail";
}
if (serc.equals("all")) {
courseList = courseService.selectCourseBySql(1,10);
pageIn(model, courseList);
httpSession.setAttribute("courseList", courseList);
System.out.println(courseList);
return "teacher/addCou";
} else if (serc.equals("sid")) {
courseList = courseService.getByCourseCid(1,10,condition);
pageIn(model, courseList);
httpSession.setAttribute("courseList", courseList);
System.out.println("sid");
return "teacher/addCou";
} else if (serc.equals("nam")) {
courseList = courseService.getByCourseCname(1,10,condition);
pageIn(model, courseList);
httpSession.setAttribute("courseList", courseList);
System.out.println(courseList);
System.out.println("cla");
return "teacher/addCou";
} else if (serc.equals("col")) {
courseList = courseService.getByCourseCol(1,10,condition);
pageIn(model, courseList);
httpSession.setAttribute("courseList", courseList);
System.out.println(courseList);
System.out.println("col");
return "teacher/addCou";
} else if (serc.equals("type")) {
courseList = courseService.getByCourseType(1,10,condition);
pageIn(model, courseList);
httpSession.setAttribute("courseList", courseList);
System.out.println(courseList);
System.out.println("pro");
return "teacher/addCou";
} else {
}
}
// 跳转页面
@RequestMapping(value = "/finalPage", method = RequestMethod.GET)
public String finalPage(HttpServletRequest request) {
queryStu(request);
return "admin/queryStudent";
}
// 修改定位
@RequestMapping(value = "/moditystu/{sid}", method = RequestMethod.GET)
public String editPre(@PathVariable("sid") String sid, HttpServletRequest request) {
List<Student> studentList = new ArrayList<Student>();
studentList = studentService.getByStudentSid(1,10,sid);
request.setAttribute("studentList", studentList);
System.out.println("-----进入修改");
return "admin/modiStudent";
}
// 修改
@RequestMapping(value = "/moditystud/{sid}", method = RequestMethod.GET)
public String update(@PathVariable("sid") String sid, Student student, HttpServletRequest request) {
int col = Integer.parseInt(student.getCollege());
int pro = Integer.parseInt(student.getProfession());
int cla = Integer.parseInt(student.getClassr());
//总感觉前端js写的有问题。
student.setCollege(arr_belongcoll[pro]);
student.setProfession(arr_belongpro[pro][col]);
student.setClassr(arr_belongcla[pro][col][cla]);
if (studentService.modifyStudent(student) != 0) {
System.out.println("----修改成功--------------------------------------------------------------------------------------------------------");
return "success";
} else {
System.out.println("----修改失败----------------------------------------------------------------");
return "fail";
return "success";
} else {
System.out.println("----修改失败----------------------------------------------------------------");
return "fail";
}
}
// 跳转页面
@RequestMapping("/managestu/{pn}")
public String manageStudent(HttpServletRequest request,
@PathVariable(value = "pn") String pn,Model model) {
int no = Integer.parseInt(pn);
PageHelper.startPage(no, 5);
List<Student> studentList = new ArrayList<Student>();
studentList = studentService.selectStudentBySql(1,100);
pageIn(model, studentList);
request.setAttribute("slist", studentList);
return "admin/queryStudent";
}
// 跳转页面
@RequestMapping("/managetea/{pn}")
public String manageTeacher(HttpServletRequest request,
@PathVariable(value = "pn") String pn,Model model) {
int no = Integer.parseInt(pn);
PageHelper.startPage(no, 5);
List<Teacher> teacherList = new ArrayList<Teacher>();
teacherList = teacherService.selectTeacherBySql(1,10);
pageIn(model, teacherList);
request.setAttribute("teacherList", teacherList);
return "admin/queryTeacher";
}
// 跳转页面
@RequestMapping("/addstu")
public String adStudent() {
return "admin/addStudent";
}
// 跳转页面
@RequestMapping("/addtea")
public String adTeacher() {
if (studentService.insertStudent(student) != 0) {
model.addAttribute("student", student);
return "success";
// return "admin/addStudent";
} else {
return "fail";
}
}
//查询全部学生方法
public void queryStu(HttpServletRequest request) {
List<Student> studentList = new ArrayList<Student>();
studentList = studentService.selectStudentBySql(1,10);
request.setAttribute("slist", studentList);
}
public void pageIn(Model model,List list) {
PageInfo page = new PageInfo(list, 5);
model.addAttribute("pageInfo", page);
}
// 查询
@RequestMapping(value = "/query/{pn}", method = RequestMethod.GET)
public String redirect(@RequestParam("serc") String serc, @RequestParam("condition") String condition,HttpServletRequest request,
@PathVariable(value = "pn") String pn,Model model) {
int no = Integer.parseInt(pn);
// System.out.println("-----"+no+"----");
List<Student> studentList = new ArrayList<Student>();
PageHelper.startPage(no, 5);
request.setAttribute("serc", serc);
request.setAttribute("condition", condition);
//查询全部
if (serc.equals("all")) {
System.out.println("------------------------------------------------------------------------------------------------");
// studentList = studentService.selectStudentBySql(1,10);
// //model.addAttribute("studentList", studentList);
// request.setAttribute("slist", studentList);
// System.out.println("00000"+request.getAttribute("slist"));
// System.out.println(studentList);
// 结课成绩查询页
@RequestMapping(value = "/endcougrade/{cid}/{cname}/{pn}", method = RequestMethod.GET)
public String endCourseGrade(@PathVariable("cid") String cid, @PathVariable("cname") String cname, Model model,
HttpSession httpSession, @PathVariable(value = "pn") String pn, HttpServletRequest request) {
int no = Integer.parseInt(pn);
PageHelper.startPage(no, 5);
List<CourseGrade> lookList = new ArrayList<CourseGrade>();
lookList = coursePlanService.getCourseGrade(1, 10, cid);
pageIn(model, lookList);
httpSession.setAttribute("lookList1", lookList);
request.setAttribute("cname", cname);
return "teacher/endCourseGrade";
}
// 添加成绩
@RequestMapping(value = "/addGrade", method = RequestMethod.POST)
public String addGrade(@RequestParam("cid") String cid, @RequestParam("sid") String sid,
@RequestParam("grade") Integer grade, Model model, HttpServletRequest request) {
Grade g = new Grade();
g.setCid(cid);
g.setSid(sid);
g.setGrade(grade);
/**
* 根据cid查学分
*/
if(grade >= 60) {
Integer credits = coursePlanService.getCreditsByCid(cid);
g.setCredits(credits);
}
gradeService.insertGrade(g);
System.out.println(g.toString());
return "teacher/endCourse";
}
}
}
// 学生登录
@RequestMapping("/studentlogin")
public ModelAndView loginStudent(@RequestParam("sid") String sid, @RequestParam("spassword") String spassword,
Model model, HttpSession httpSession, HttpServletRequest httpRequest) {
Student student = new Student();
student = studentService.getByStuSid(sid);
if (studentService.queryByNamePwd(sid, spassword) != null) {
httpSession.setAttribute("sid", sid);
httpSession.setAttribute("sname", student.getSname());
return new ModelAndView(new RedirectView("../student/studentFace.jsp"));
} else {
httpRequest.setAttribute("msg","账号或密码不正确,登录失败!");
return new ModelAndView(new RedirectView("../fail.jsp"));
}
}
// 学生退出登录
@RequestMapping("/studentlogout")
public ModelAndView studentLogout(HttpSession httpSession) {
httpSession.removeAttribute("sid");
httpSession.removeAttribute("sname");
httpSession.removeAttribute("courseList");
httpSession.removeAttribute("ssrList");
httpSession.removeAttribute("sesList");
return new ModelAndView(new RedirectView("/StudentInfo/index.jsp"));
}
// 教师登录
@RequestMapping("/teacherlogin")
public ModelAndView loginTeacher(@RequestParam("tid") String tid, @RequestParam("tpassword") String tpassword,
Model model, HttpSession httpSession) {
if (teacherService.queryByNamePwd(tid, tpassword) != null) {
Teacher teacher = new Teacher();
teacher = teacherService.getByTeaTid(tid);
// model.addAttribute("tid", tid);
httpSession.setAttribute("tid", tid);
httpSession.setAttribute("tname", teacher.getTname());
// httpSession.setAttribute("teachername", teacher.getTname());
return new ModelAndView(new RedirectView("../teacher/teacherFace.jsp"));
} else {
return new ModelAndView(new RedirectView("../fail.jsp"));
}
request.setAttribute("courseList", courseList);
System.out.println(courseList);
System.out.println("cla");
return "student/selCourse";
} else if (serc.equals("col")) {
courseList = courseService.getByCourseCol(1, 10, condition);
pageIn(model, courseList);
request.setAttribute("courseList", courseList);
System.out.println(courseList);
System.out.println("col");
return "student/selCourse";
} else if (serc.equals("type")) {
courseList = courseService.getByCourseType(1, 10, condition);
pageIn(model, courseList);
request.setAttribute("courseList", courseList);
System.out.println(courseList);
System.out.println("pro");
return "student/selCourse";
} else {
courseList = courseService.selectCourseBySql(1, 10);
pageIn(model, courseList);
request.setAttribute("courseList", courseList);
System.out.println(courseList);
return "student/selCourse";
}
}
// 查询,根据cid查询老师
@RequestMapping(value = "/selcou/{cid}", method = RequestMethod.GET)
public String selCou(@PathVariable(value = "cid") String cid, Model model) {
// 代优化
List<CoursePlan> lists = null;
lists = coursePlanService.getTidByCoursePlanCid(1, 10, cid);
System.out.println("------" + lists.size());
Teacher teacher = new Teacher();
Course course = new Course();
if (lists.size() != 0) {
System.out.println("-----进入选课");
}
// 查询,根据cid查询老师
@RequestMapping(value = "/selcou/{cid}", method = RequestMethod.GET)
public String selCou(@PathVariable(value = "cid") String cid, Model model) {
// 代优化
List<CoursePlan> lists = null;
lists = coursePlanService.getTidByCoursePlanCid(1, 10, cid);
System.out.println("------" + lists.size());
Teacher teacher = new Teacher();
Course course = new Course();
if (lists.size() != 0) {
System.out.println("-----进入选课");
String tid = lists.get(0).getTid();
teacher = teacherService.getByTeaTid(tid);
model.addAttribute("tname", teacher.getTname());
model.addAttribute("inroduction", teacher.getIntroduction());
System.out.println(teacher.getIntroduction() + "-----------------------");
course = courseService.getByCouCid(cid);
model.addAttribute("cname", course.getCname());
model.addAttribute("cid", cid);
return "student/seling";
} else {
System.out.println("-----进入无教师选课");
course = courseService.getByCouCid(cid);
model.addAttribute("cname", course.getCname());
model.addAttribute("cid", cid);
return "student/noseling";
}
}
// 加入课程
@RequestMapping("/seling")
public String confirmSelect(@RequestParam("cid") String cid, @RequestParam("sid") String sid, Model model,
HttpSession httpSession, HttpServletRequest httpRequest) {
// 判断是否加入过此课程
if (selectCourseService.existCourse(cid, sid) != null) {
httpRequest.setAttribute("msg", "已经加入过该课程,不能重复加入!");
System.out.println("已经加入过该课程,不能重复加入!");
return "fail";
}
if (selectCourseService.selectCourse(cid, sid) != 0) {
System.out.println(cid);
System.out.println(sid);
return "success";
} else {
return "fail";
List<Teacher> teacherList = new ArrayList<Teacher>();
teacherList = teacherService.getByTeacherTid(1,10,tid);
//model.addAttribute("teacherList", teacherList);
request.setAttribute("teacherList", teacherList);
return "admin/modiTeacher";
}
// 修改
@RequestMapping(value = "/modityTeac/{tid}", method = RequestMethod.GET)
public String update(@PathVariable("tid") String tid, Teacher teacher, HttpServletRequest request) {
if (teacherService.modifyTeacher(teacher) != 0) {
return "success";
} else {
return "fail";
}
}
}
httpSession.removeAttribute("sname");
httpSession.removeAttribute("courseList");
httpSession.removeAttribute("ssrList");
httpSession.removeAttribute("sesList");
return new ModelAndView(new RedirectView("/StudentInfo/index.jsp"));
}
// 教师登录
@RequestMapping("/teacherlogin")
public ModelAndView loginTeacher(@RequestParam("tid") String tid, @RequestParam("tpassword") String tpassword,
Model model, HttpSession httpSession) {
if (teacherService.queryByNamePwd(tid, tpassword) != null) {
Teacher teacher = new Teacher();
teacher = teacherService.getByTeaTid(tid);
// model.addAttribute("tid", tid);
httpSession.setAttribute("tid", tid);
httpSession.setAttribute("tname", teacher.getTname());
// httpSession.setAttribute("teachername", teacher.getTname());
return new ModelAndView(new RedirectView("../teacher/teacherFace.jsp"));
} else {
return new ModelAndView(new RedirectView("../fail.jsp"));
}
}
// 教师退出登录
@RequestMapping("/teacherlogout")
public ModelAndView teacherLogout(HttpSession httpSession) {
httpSession.removeAttribute("tid");
httpSession.removeAttribute("tname");
httpSession.removeAttribute("couList");
httpSession.removeAttribute("sesList");
httpSession.removeAttribute("lookList");
return new ModelAndView(new RedirectView("/StudentInfo/index.jsp"));
}
}
g.setCredits(credits);
}
gradeService.insertGrade(g);
System.out.println(g.toString());
return "teacher/endCourse";
}
}
/**
*
* @ProjectName: StudentInfo
* @Package: net.fuzui.StudentInfo.handler
if (selectCourseService.selectCourse(cid, sid) != 0) {
System.out.println(cid);
System.out.println(sid);
return "success";
} else {
return "fail";
}
}
// 退出
@RequestMapping("/backseling/{cid}")
public ModelAndView backConfirmSelect(@PathVariable(value = "cid") String cid) {
return new ModelAndView(new RedirectView("/StudentInfo/StudentHandler/selqueryy/1"));
}
// 跳转页面
@RequestMapping("/selqueryy/{pn}")
public String selQueryy(HttpServletRequest request, @PathVariable(value = "pn") String pn, Model model) {
int no = Integer.parseInt(pn);
List<Course> courseList = new ArrayList<Course>();
PageHelper.startPage(no, 5);
courseList = courseService.selectCourseBySql(1, 10);
pageIn(model, courseList);
request.setAttribute("courseList", courseList);
return "student/selCourse";
}
// 学生查询本人选课
@RequestMapping(value = "/selcouresult/{sid}/{pn}", method = RequestMethod.GET)
public String selcouresult(@PathVariable("sid") String sid, StuSelectResult ssr, HttpServletRequest request,
@PathVariable(value = "pn") String pn, Model model) {
List<StuSelectResult> ssrList = new ArrayList<StuSelectResult>();
ssrList = selectCourseService.getSCBySid(1, 10, sid);
pageIn(model, ssrList);
request.setAttribute("ssrList", ssrList);
return "student/selectedCourse";
}
return new ModelAndView(new RedirectView("../fail.jsp"));
}
}
// 教师退出登录
@RequestMapping("/teacherlogout")
public ModelAndView teacherLogout(HttpSession httpSession) {
httpSession.removeAttribute("tid");
httpSession.removeAttribute("tname");
httpSession.removeAttribute("couList");
httpSession.removeAttribute("sesList");
httpSession.removeAttribute("lookList");
return new ModelAndView(new RedirectView("/StudentInfo/index.jsp"));
}
}
/**