作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目为基于WEB的教务管理系统。
主要系统功能包括:
学生管理:显示所有学生、添加学生;
课程管理:显示所有课程、添加课程;
学院管理:显示所有学院、添加学院;
专业管理:所有专业、设置专业;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目: 是
技术栈
1. 后端:servlet
2. 前端:JSP+css+javascript+layui
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,导入成功后请执行maven clean;
maven install命令,然后运行;
3. 将项目中util/ConnectionUtil.java修改数据库信息
4. 运行项目,在浏览器中输入http://localhost:8080/student-sys 登录
管理员用户名:123456 密码:123456
运行截图
文章来源:https://www.toymoban.com/news/detail-503447.html
相关代码
AcademyController
package controller;
import common.Pager;
import domain.AcademyDomain;
import domain.AdminDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import service.AcademyService;
import service.AdminService;
import service.CourseService;
import service.MajorService;
import service.StudentService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/students")
public class AcademyController {
@Autowired
private AcademyService service;
@Autowired
private CourseService courseService;
@Autowired
private MajorService majorService;
public CourseService getCourseService() {
return courseService;
}
public void setCourseService(CourseService courseService) {
this.courseService = courseService;
}
public MajorService getMajorService() {
return majorService;
}
public void setMajorService(MajorService majorService) {
this.majorService = majorService;
}
public AcademyService getService() {
return service;
}
public void setService(AcademyService service) {
this.service = service;
}
//显示所有学院信息
@RequestMapping("/showAllAcademy.do")
public ModelAndView findAllAcademy( Integer page,Integer perPage,HttpServletRequest request){
ModelAndView mv=new ModelAndView();
HttpSession session = request.getSession();
String error = (String) session.getAttribute("error");
request.setAttribute("error", error);
mv.setViewName("showAllAcademy");
session.removeAttribute("error");
Pager<AcademyDomain> list=service.findAllAcademy(page,perPage);
mv.addObject("Pager",list);
return mv;
}
//删除学院
@RequestMapping("/delAcademy.do")
public ModelAndView delAcademy(Integer id,HttpServletRequest req){
HttpSession session = req.getSession();
String error = "";
if (majorService.findByAId(id)) {
error= "该学院下有专业,不能删除该学院!!!";
session.setAttribute("error", error);
}else {
if (courseService.findByAId(id)) {
error= "该学院下有课程,不能删除该学院!!!";
session.setAttribute("error", error);
}else {
service.delAcademy(id);
}
}
return new ModelAndView("redirect:/students/showAllAcademy.do");
}
//添加预处理
@RequestMapping("/preAddAcademy.do")
public ModelAndView preAddAcademy(){
ModelAndView mv=new ModelAndView();
mv.setViewName("addAcademy");
return mv;
}
//添加学院
@RequestMapping("/addAcademy.do")
public ModelAndView addAcademy(AcademyDomain domain){
service.addAcademy(domain);
return new ModelAndView("redirect:/students/showAllAcademy.do");
}
//修改学院
@RequestMapping("/modifyAcademy.do")
public ModelAndView modifyAcademy(Integer id,AcademyDomain domain){
service.modifyAcademy(id, domain);
return new ModelAndView("redirect:/students/showAllAcademy.do");
}
}
AdminController
package controller;
import domain.AdminDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import service.AdminService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
@Controller
@RequestMapping("/students")
public class AdminController {
@Autowired
private AdminService service;
public AdminService getService() {
return service;
}
public void setService(AdminService service) {
this.service = service;
}
// 判断登录
@RequestMapping("/login.do")
public ModelAndView doLogin(AdminDomain ae, HttpServletRequest req) {
HttpSession session = req.getSession();
List<AdminDomain> list = service.findAll();
ModelAndView mv = new ModelAndView();
for (AdminDomain ad : list) {
if (ae.getName().equals(ad.getName()) && ae.getPassword().equals(ad.getPassword())) {
mv.addObject("ae", ae);
session.setAttribute("user", ae);
mv.setViewName("Main");
return mv;
}
}
mv.setViewName("loginFailure");
return mv;
}
}
CourseController
package controller;
import domain.AcademyDomain;
import domain.CourseDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import service.AcademyService;
import service.CourseService;
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Controller
@RequestMapping("/students")
public class CourseController {
@Autowired
private CourseService service;
@Autowired
private AcademyService aService;
public AcademyService getaService() {
return aService;
}
public void setaService(AcademyService aService) {
this.aService = aService;
}
public CourseService getService() {
return service;
}
public void setService(CourseService service) {
this.service = service;
}
@RequestMapping("/showAllCourse.do")
public ModelAndView showAllCourse(){
ModelAndView mv=new ModelAndView();
mv.setViewName("showAllCourse");
List<CourseDomain> list=service.findAllCourse();
mv.addObject("list",list);
return mv;
}
//添加课程预处理
@RequestMapping("/preAddCourse.do")
public ModelAndView preAdd(){
ModelAndView mv=new ModelAndView();
List<AcademyDomain> list=aService.findAllAcademy1();
mv.addObject("list",list);
mv.setViewName("addcourse");
return mv;
}
//
@RequestMapping("/addCourse.do")
public ModelAndView addCourse(CourseDomain domain,HttpServletRequest request,HttpServletResponse response) throws Exception{
request.setCharacterEncoding("UTF-8" );
response.setCharacterEncoding("UTF-8");
service.addCourse(domain);
return new ModelAndView("redirect:/students/showAllCourse.do");
}
@RequestMapping("/delCourse.do")
public ModelAndView delCourse(Integer id){
service.delCourse(id);
return new ModelAndView("redirect:/students/showAllCourse.do");
}
@RequestMapping("/preModifyCourse.do")
public ModelAndView preModifyCourse(Integer id) throws Exception{
ModelAndView mv=new ModelAndView();
List<AcademyDomain> alist=aService.findAllAcademy1();
CourseDomain courseDomain = service.findById(id);
mv.addObject("courseDomain", courseDomain);
mv.addObject("alist",alist);
mv.setViewName("modifyCourse");
return mv;
}
@RequestMapping("/modifyCourse.do")
public ModelAndView modifyCourse(Integer id,CourseDomain domain,HttpServletRequest request,HttpServletResponse response) throws Exception{
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
service.modifyCourse(id, domain);
return new ModelAndView("redirect:/students/showAllCourse.do");
}
}
MajorController
package controller;
import domain.AcademyDomain;
import domain.MajorDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import service.AcademyService;
import service.MajorService;
import service.StudentService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/students")
public class MajorController {
@Autowired
private MajorService service;
@Autowired
private AcademyService aService;
@Autowired
private StudentService studentService;
public StudentService getStudentService() {
return studentService;
}
public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}
public AcademyService getaService() {
return aService;
}
public void setaService(AcademyService aService) {
this.aService = aService;
}
public MajorService getService() {
return service;
}
public void setService(MajorService service) {
this.service = service;
}
//显示所有
@RequestMapping("/showAllMajor.do")
public ModelAndView findAll(HttpServletRequest request){
HttpSession session = request.getSession();
ModelAndView mv=new ModelAndView();
String error = (String) session.getAttribute("error");
request.setAttribute("error", error);
mv.setViewName("showAllMajor");
session.removeAttribute("error");
List<MajorDomain> list=service.findAll();
mv.addObject("list",list);
return mv;
}
//添加预处理
@RequestMapping("/preAddMajor.do")
public ModelAndView preAdd(){
ModelAndView mv=new ModelAndView();
List<AcademyDomain> majorList=aService.findAllAcademy1();
mv.addObject("majorList",majorList);
mv.setViewName("addMajor");
return mv;
}
//添加专业
@RequestMapping("/addMajor.do")
public ModelAndView addMajor(MajorDomain domain,HttpServletRequest request,HttpServletResponse response) throws Exception{
request.setCharacterEncoding("UTF-8" );
response.setCharacterEncoding("UTF-8");
service.addMajor(domain);
return new ModelAndView("redirect:/students/showAllMajor.do");
}
//删除
@RequestMapping("/delMajor.do")
public ModelAndView delMajor(Integer id,HttpServletRequest req){
HttpSession session = req.getSession();
String error = "";
if (studentService.findByMajorId(id)) {
error= "该专业类别下有学生,不能删除该专业!!!";
session.setAttribute("error", error);
}else {
service.delMajor(id);
}
return new ModelAndView("redirect:/students/showAllMajor.do");
}
//修改
@RequestMapping("/preModifyMajor.do")
public ModelAndView preModifyMajor(Integer id ){
ModelAndView mv=new ModelAndView();
List<AcademyDomain> academList=aService.findAllAcademy1();
MajorDomain majorDomain = service.findById(id);
mv.addObject("majorDomain",majorDomain);
mv.addObject("majorList",academList);
mv.setViewName("modifyMajor");
return mv;
}
//修改
@RequestMapping("/modifyMajor.do")
public ModelAndView modifyMajor(Integer id ,MajorDomain domain,HttpServletRequest request,HttpServletResponse response) throws Exception{
request.setCharacterEncoding("UTF-8" );
response.setCharacterEncoding("UTF-8");
service.modifyMajor(id, domain);
return new ModelAndView("redirect:/students/showAllMajor.do");
}
}
StudentController
package controller;
import common.Pager;
import domain.MajorDomain;
import domain.StudentDomain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import service.MajorService;
import service.StudentService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*
* MVC --> Model + View + Controller
* ModelAndView 封装业务数据以及逻辑视图名
* Bean对象 --> 作用域 ( singleton prototype)
*/
@Controller
@RequestMapping("/students")
public class StudentController {
@Autowired // 自动注入 ( byName byType)
private StudentService service;
@Autowired
private MajorService majorservice;
public MajorService getMajorservice() {
return majorservice;
}
public void setMajorservice(MajorService majorservice) {
this.majorservice = majorservice;
}
public StudentService getService() {
return service;
}
public void setService(StudentService service) {
this.service = service;
}
// 添加学生预处理
@RequestMapping("/preAdd.do")
public ModelAndView preAddStudent() {
List<MajorDomain> list = null;
list = majorservice.findAll();
ModelAndView mv = new ModelAndView();
mv.addObject("list", list);
mv.setViewName("addstudent");
return mv;
}
@RequestMapping("/create.do")
public ModelAndView createStudent(StudentDomain domain, HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
service.addStudent(domain);
return new ModelAndView("redirect:/students/findForPager.do");
}
// 显示所有
@RequestMapping("/findForPager.do")
// page, perPage 数据绑定
// 获取参数
public ModelAndView findForPager(@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer perPage) {
ModelAndView mv = new ModelAndView();
Pager<StudentDomain> pager = service.findForPager(page, perPage);
mv.setViewName("showAll");
mv.addObject("pager", pager);
return mv;
}
// 删除
@RequestMapping("/delStudents.do")
public ModelAndView delStuent(String id) {
service.DelStudent(id);
return new ModelAndView("redirect:/students/findForPager.do");
}
// 修改
@RequestMapping("/preModifyStudents.do")
public ModelAndView preModifyStudent(Integer id) throws Exception {
List<MajorDomain> list = null;
list = majorservice.findAll();
ModelAndView mv = new ModelAndView();
StudentDomain studentDomain = service.findById(id);
mv.addObject("mojorList", list);
mv.addObject("student", studentDomain);
mv.setViewName("modifystudent");
return mv;
}
// 修改
@RequestMapping("/modifyStudents.do")
public ModelAndView modifyStudent(Integer id, StudentDomain stu, HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
service.Modify(id, stu);
return new ModelAndView("redirect:/students/findForPager.do");
}
// 按姓名查找
@RequestMapping("/findByName.do")
public ModelAndView findByName(String name, HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
ModelAndView mv = new ModelAndView();
Pager<StudentDomain> list = service.findByName(name);
mv.setViewName("showAll");
mv.addObject("pager", list);
return mv;
}
}
如果也想学习本系统,下面领取。关注并回复:125jsp文章来源地址https://www.toymoban.com/news/detail-503447.html
到了这里,关于Java项目:基于JavaWeb的教务管理系统的设计与实现的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!