基于javaweb+mysql的springboot学生信息管理系统(java+springboot+html+layui+maven+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot学生信息管理系统(java+springboot+html+layui+maven+mysql)
一、项目简述
功能包括: 三角色管理: 学生,教师,管理员,在线选课,成绩录入,学生管理,选课管理,教室管理等等。学生管理可以查看所有学生并操作、添加学生;查看学生选报课程详情等等。教师管理可以查看所有教师并操作、添加教师等等。班级管理可以查看所有班级信息并操作、添加班级等等。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等;
/**
*/
@Controller
public class TeacherController {
@Autowired
TeacherDao teacherDao;
@Autowired
CourseDao courseDao;
/*
* @Param: [model]
* @Return: java.lang.String
* @Description: 转发到教师列表页面
*/
@RequestMapping("/back/teacher/list")
public String toStudentList(Model model) {
List<Teacher> teachers = teacherDao.queryAllTeacher();
model.addAttribute("teachers", teachers);
List<Course> teachcourses = new ArrayList<>();
for (Teacher teacher : teachers) {
teachcourses.add(teacherDao.queryTeachCourseByID(teacher.getTeacherId()));
}
model.addAttribute("teachcourses", teachcourses);
List<Course> courses = courseDao.queryAllCourse();
model.addAttribute("courses", courses);
studentDao.updateStudentInfo(student);
return "redirect:/front/info";
}
@PostMapping("/front/info/{studentId}")
public String updatePassword(@PathVariable("studentId") String studentId, @Param("current_password") String current_password, @Param("password") String password) {
studentDao.updateStudentPassword(studentId, password);
return "redirect:/logout";
}
}
/**
*/
@Controller
public class TeacherController {
@Autowired
TeacherDao teacherDao;
@Autowired
CourseDao courseDao;
/*
* @Param: [model]
* @Return: java.lang.String
public String toSelectCourse(HttpSession session, Model model) {
long time = new Date().getTime();
List<Course> list = newList(courseDao.queryAllCourse());
model.addAttribute("courses", list);
List<Course> selectCourses = newList(studentDao.querySelectCourseByStudentID((String) session.getAttribute("LoginUser")));
model.addAttribute("selectCourses", selectCourses);
String msg = (String) session.getAttribute("msg");
if (msg != null) {
model.addAttribute("msg", msg);
session.removeAttribute("msg");
}
return "front/selectcourse";
}
@GetMapping("/front/selectcourse/{courseId}")
public String selectCourse(@PathVariable("courseId") String courseId, HttpSession session) {
String loginUser = (String) session.getAttribute("LoginUser");
List<Course> selectCourses = studentDao.querySelectCourseByStudentID(loginUser);
for (Course course : selectCourses) {
if (course.getCourseId().equals(courseId)) {
session.setAttribute("msg", "选课失败,您已选报此课程,请勿重复选报");
return "redirect:/front/selectcourse";
}
}
studentDao.setSelectCourse(loginUser, courseId);
session.setAttribute("msg", "选课成功,请注意课程安排");
return "redirect:/front/selectcourse";
}
@GetMapping("/front/selectcourse/delete/{courseId}")
public String deleteSelectCourse(@PathVariable("courseId") String courseId, HttpSession session) {
String loginUser = (String) session.getAttribute("LoginUser");
studentDao.deleteSelectCourse(loginUser, courseId);
session.setAttribute("msg", "退选成功,请注意查看");
return "redirect:/front/selectcourse";
}
//更新课程状态
List<Course> newList(List<Course> courses) {
List<Course> list = new ArrayList<>();
/**
*/
@Controller
public class StudentController {
@Autowired
StudentDao studentDao;
@Autowired
ClassDao classDao;
@Autowired
CourseDao courseDao;
/*
* @Param: [model]
* @Return: java.lang.String
* @Description: 请求转发学生列表页面(所查学生顺序为按学号降序)
*/
@RequestMapping("/back/student/list")
public String toStudentList(Model model) {
List<Student> students = studentDao.queryAllStudent();
model.addAttribute("students", students);
List<Class> classes = classDao.queryAllClass();
model.addAttribute("classes", classes);
return "back/student/list";
}
/*
* @Param: [student]
Student student = studentDao.queryStudentByUsername(loginUser);
model.addAttribute("stu", student);
return "front/info";
}
@PostMapping("/front/info")
public String updateInfo(Student student) {
studentDao.updateStudentInfo(student);
return "redirect:/front/info";
}
@PostMapping("/front/info/{studentId}")
public String updatePassword(@PathVariable("studentId") String studentId, @Param("current_password") String current_password, @Param("password") String password) {
studentDao.updateStudentPassword(studentId, password);
return "redirect:/logout";
}
}
/**
*/
@Controller
}
/*
* @Param: []
* @Return: java.lang.String
* @Description: 转发到帮助导入教师页面
*/
@RequestMapping("/back/help/teacher")
public String toHelpTeacher() {
return "back/help/teacher";
}
}
/**
*/
@WebFilter(filterName = "LoginFilter")
public class LoginFilter implements Filter {
private String[] pathList;
public void destroy() {
System.out.println("LoginFilter已结束");
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) resp;
HttpSession session = request.getSession();
String requestPath = request.getServletPath();
if (containsPath(requestPath) || session.getAttribute("LoginUser") != null) {
if (session.getAttribute("LoginUser") != null) {
String classify = (String) session.getAttribute("classify");
if (requestPath.contains("/front/" + classify) || (classify.equals("administrator") && requestPath.contains("/back"))) {
chain.doFilter(req, resp);
} else {
String url = "/studentmanage";
if (classify.equals("administrator")) {
url += "/back";
} else {
url += "/front/" + classify;
}
studentDao.deleteSelectCourse(loginUser, courseId);
session.setAttribute("msg", "退选成功,请注意查看");
return "redirect:/front/selectcourse";
}
//更新课程状态
List<Course> newList(List<Course> courses) {
List<Course> list = new ArrayList<>();
long time = new Date().getTime();
for (Course course : courses) {
if (time - course.getBeginDate().getTime() >= 0) {
if (course.getEndDate().getTime() + 1000 * 60 * 60 * 24 > time) {
course.setStatus("进行中");
list.add(0, course);
} else {
course.setStatus("已结束");
list.add(course);
}
} else {
course.setStatus("未开始");
list.add(course);
}
}
return list;
}
@RequestMapping("/front/info")
public String toInfo(HttpSession session, Model model) {
String loginUser = (String) session.getAttribute("LoginUser");
Student student = studentDao.queryStudentByUsername(loginUser);
model.addAttribute("stu", student);
return "front/info";
}
@PostMapping("/front/info")
public String updateInfo(Student student) {
studentDao.updateStudentInfo(student);
return "redirect:/front/info";
}
@PostMapping("/front/info/{studentId}")
public String updatePassword(@PathVariable("studentId") String studentId, @Param("current_password") String current_password, @Param("password") String password) {
return "front/student/selectcourse";
}
/*
* @Param:
* @Return:
* @Description: 学生选课操作
*/
@GetMapping("/front/student/selectcourse/{courseId}")
public String selectCourse(@PathVariable("courseId") String courseId, HttpSession session) {
String loginUser = (String) session.getAttribute("LoginUser");
List<Course> selectCourses = studentDao.querySelectCourseByStudentID(loginUser);
for (Course course : selectCourses) {
if (course.getCourseId().equals(courseId)) {
session.setAttribute("msg", "选课失败,您已选报此课程,请勿重复选报");
return "redirect:/front/student/selectcourse";
}
}
studentDao.setSelectCourse(loginUser, courseId);
session.setAttribute("msg", "选课成功,请注意课程安排");
return "redirect:/front/student/selectcourse";
}
/*
* @Param: [courseId, session]
* @Return: java.lang.String
* @Description: 学生退课操作
*/
@GetMapping("/front/student/selectcourse/delete/{courseId}")
public String deleteSelectCourse(@PathVariable("courseId") String courseId, HttpSession session) {
String loginUser = (String) session.getAttribute("LoginUser");
studentDao.deleteSelectCourse(loginUser, courseId);
session.setAttribute("msg", "退选成功,请注意查看");
return "redirect:/front/student/selectcourse";
}
//更新课程状态
List<Course> newList(List<Course> courses) {
List<Course> list = new ArrayList<>();
long time = new Date().getTime();
for (Course course : courses) {
if (time - course.getBeginDate().getTime() >= 0) {
@GetMapping("/back/course/selectcourse")
public String toCourseSelectCourse(Model model) {
List<SelectCourseStudents> selectCourseStudents = newList(courseDao.selectCourseStudents());
model.addAttribute("selectCourseStudents", selectCourseStudents);
List<Class> classes = classDao.queryAllClass();
model.addAttribute("classes", classes);
return "back/course/selectcourse";
}
//更新课程状态
List<SelectCourseStudents> newList(List<SelectCourseStudents> selectCourseStudents) {
List<SelectCourseStudents> list = new ArrayList<>();
long time = new Date().getTime();
for (SelectCourseStudents scs : selectCourseStudents) {
Course course = scs.getCourse();
if (time - course.getBeginDate().getTime() >= 0) {
if (course.getEndDate().getTime() + 1000 * 60 * 60 * 24 > time) {
course.setStatus("进行中");
list.add(0, scs);
} else {
course.setStatus("已结束");
list.add(scs);
}
} else {
course.setStatus("未开始");
list.add(scs);
}
}
return list;
}
}
long time = new Date().getTime();
List<Course> list = newList(courseDao.queryAllCourse());
model.addAttribute("courses", list);
List<Course> selectCourses = newList(studentDao.querySelectCourseByStudentID((String) session.getAttribute("LoginUser")));
model.addAttribute("selectCourses", selectCourses);
String msg = (String) session.getAttribute("msg");
if (msg != null) {
model.addAttribute("msg", msg);
session.removeAttribute("msg");
}
return "front/selectcourse";
}
@GetMapping("/front/selectcourse/{courseId}")
public String selectCourse(@PathVariable("courseId") String courseId, HttpSession session) {
String loginUser = (String) session.getAttribute("LoginUser");
List<Course> selectCourses = studentDao.querySelectCourseByStudentID(loginUser);
for (Course course : selectCourses) {
if (course.getCourseId().equals(courseId)) {
session.setAttribute("msg", "选课失败,您已选报此课程,请勿重复选报");
return "redirect:/front/selectcourse";
}
}
studentDao.setSelectCourse(loginUser, courseId);
session.setAttribute("msg", "选课成功,请注意课程安排");
return "redirect:/front/selectcourse";
}
@GetMapping("/front/selectcourse/delete/{courseId}")
public String deleteSelectCourse(@PathVariable("courseId") String courseId, HttpSession session) {
String loginUser = (String) session.getAttribute("LoginUser");
studentDao.deleteSelectCourse(loginUser, courseId);
session.setAttribute("msg", "退选成功,请注意查看");
return "redirect:/front/selectcourse";
}
//更新课程状态
List<Course> newList(List<Course> courses) {
List<Course> list = new ArrayList<>();
long time = new Date().getTime();
for (Course course : courses) {
if (time - course.getBeginDate().getTime() >= 0) {
if (course.getEndDate().getTime() + 1000 * 60 * 60 * 24 > time) {
course.setStatus("进行中");
list.add(0, course);
} else {
course.setStatus("已结束");
list.add(course);
}
} else {
course.setStatus("未开始");
/**
*/
@Controller
public class ClassController {
@Autowired
ClassDao classDao;
@Autowired
CourseDao courseDao;
/*
* @Param: [model]
* @Return: java.lang.String
* @Description: 转发到班级列表页面
*/
@RequestMapping("/back/class/list")
public String toClassList(Model model) {
List<Class> classes = classDao.queryAllClass();
model.addAttribute("classes", classes);
return "back/class/list";
}
/*
* @Param: [addclass]
* @Return: java.lang.String
* @Description: 添加班级
*/
@PostMapping("/back/class/add")
public String addClass(Class addclass) {
classDao.addClass(addclass);
return "redirect:/back/class/list";
}
/*
* @Param: [classId]
* @Return: java.lang.String
* @Description: 删除班级。注意点:删除班级前需要删除本班所有学生,删除学生之前需要删除学生的选课信息。
noticeDao.deleteNotice(noticeId);
return "redirect:/back/notice";
}
/*
* @Param: [deleteall]
* @Return: java.lang.String
* @Description: 批量删除公告
*/
@PostMapping("/back/notice/delete")
public String deleteNotices(@Param("deleteall") String deleteall) {
String[] deleteNotices = deleteall.split(",");
for (String noticeId : deleteNotices) {
noticeDao.deleteNotice(noticeId);
}
return "redirect:/back/notice";
}
/*
* @Param: [notice]
* @Return: java.lang.String
* @Description: 修改公告内容
*/
@PostMapping("/back/notice/info")
public String updateNotice(Notice notice) {
noticeDao.updateNotice(notice);
return "redirect:/back/notice";
}
/*
* @Param: []
* @Return: java.lang.String
* @Description: 转发到帮助导入课程页面
*/
@RequestMapping("/back/help/course")
public String toHelpCourse() {
return "back/help/course";
}
/*
* @Param: []
* @Return: java.lang.String
* @Description: 转发到帮助导入学生页面
*/
@RequestMapping("/back/help/student")
/**
*/
@Controller
public class FrontController {
@Autowired
StudentDao studentDao;
@Autowired
NoticeDao noticeDao;
@Autowired
CourseDao courseDao;
/*
* @Param: [model]
* @Return: java.lang.String
* @Description: 转发到前台主页
*/
@RequestMapping({"/front", "/front/index.html"})
public String toFrontIndex(Model model) {
List<Notice> notices = noticeDao.queryAllNotice();
model.addAttribute("notices", notices);
return "front/index";
}
@RequestMapping({"/front/selectcourse"})
public String toSelectCourse(HttpSession session, Model model) {
long time = new Date().getTime();
List<Course> list = newList(courseDao.queryAllCourse());
model.addAttribute("courses", list);
List<Course> selectCourses = newList(studentDao.querySelectCourseByStudentID((String) session.getAttribute("LoginUser")));
* @Description: 转发到帮助导入学生页面
*/
@RequestMapping("/back/help/student")
public String toHelpStudent() {
return "back/help/student";
}
/*
* @Param: []
* @Return: java.lang.String
* @Description: 转发到帮助导入教师页面
*/
@RequestMapping("/back/help/teacher")
public String toHelpTeacher() {
return "back/help/teacher";
}
}
/**
*/
@WebFilter(filterName = "LoginFilter")
public class LoginFilter implements Filter {
private String[] pathList;
public void destroy() {
System.out.println("LoginFilter已结束");
}
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
/**
*/
@Controller
public class LoginController {
@Autowired
StudentDao studentDao;
@Autowired
TeacherDao teacherDao;
/*
* @Param: []
* @Return: java.lang.String
* @Description: 请求转发到登录页面
*/
@RequestMapping("/index.html")
public String toLogin(HttpSession session) {
if (session.getAttribute("LoginUser") != null) {
return "redirect:/back";
}
return "login";
}
@Value("${administrator.username}")
String admin_useranme;
@Value("${administrator.password}")
String admin_password;
/*
* @Param: [username, password, model, session]
* @Return: java.lang.String
* @Description: 判断用户是否登录成功(管理员账号密码存储在yml配置文件里),若登录成功则重定向到对应的首页;否则请求转发回登录页面,将错误信息传回页面显示(并将账号密码回传用于回填)
*/
@PostMapping("/login")
public String checkLogin(@Param("username") String username, @Param("password") String password, Model model, HttpSession session) {
if (username.equals(admin_useranme) && password.equals(admin_password)) {
session.setAttribute("LoginUser", username);
session.setAttribute("classify", "administrator");
return "redirect:/back/index.html";
} else {
Student student = studentDao.queryStudentByUsername(username);
@Autowired
ClassDao classDao;
@Autowired
StudentDao studentDao;
/*
* @Param: [model]
* @Return: java.lang.String
* @Description: 前台教师首页
*/
@RequestMapping("/front/teacher")
public String toFrontIndex(Model model) {
List<Notice> notices = noticeDao.queryAllNotice();
model.addAttribute("notices", notices);
return "front/teacher/index";
}
/*
* @Param: [session, model]
* @Return: java.lang.String
* @Description: 前台教师教授课程页面
*/
@RequestMapping("/front/teacher/courseinfo")
public String toCourseInfo(HttpSession session, Model model) {
String loginUser = (String) session.getAttribute("LoginUser");
Course course = teacherDao.queryTeachCourseByID(loginUser);
long time = new Date().getTime();
if (time - course.getBeginDate().getTime() >= 0) {
if (course.getEndDate().getTime() + 1000 * 60 * 60 * 24 > time) {
course.setStatus("进行中");
} else {
course.setStatus("已结束");
}
} else {
course.setStatus("未开始");
}
model.addAttribute("course", course);
List<Student> students = courseDao.queryCourseStudentsByID(course.getCourseId());
model.addAttribute("students", students);
List<Class> classes = classDao.queryAllClass();
model.addAttribute("classes", classes);
return "front/teacher/courseinfo";
}
/*
* @Param: [session, model]
return "redirect:/front/selectcourse";
}
//更新课程状态
List<Course> newList(List<Course> courses) {
List<Course> list = new ArrayList<>();
long time = new Date().getTime();
for (Course course : courses) {
if (time - course.getBeginDate().getTime() >= 0) {
if (course.getEndDate().getTime() + 1000 * 60 * 60 * 24 > time) {
course.setStatus("进行中");
list.add(0, course);
} else {
course.setStatus("已结束");
list.add(course);
}
} else {
course.setStatus("未开始");
list.add(course);
}
}
return list;
}
@RequestMapping("/front/info")
public String toInfo(HttpSession session, Model model) {
String loginUser = (String) session.getAttribute("LoginUser");
Student student = studentDao.queryStudentByUsername(loginUser);
model.addAttribute("stu", student);
return "front/info";
}
@PostMapping("/front/info")
public String updateInfo(Student student) {
studentDao.updateStudentInfo(student);
return "redirect:/front/info";
}
@PostMapping("/front/info/{studentId}")
public String updatePassword(@PathVariable("studentId") String studentId, @Param("current_password") String current_password, @Param("password") String password) {
studentDao.updateStudentPassword(studentId, password);
return "redirect:/logout";
}
}
/**
*/
@Controller
public class StuController {
@Autowired
StudentDao studentDao;
@Autowired
NoticeDao noticeDao;
@Autowired
CourseDao courseDao;
@Autowired
ClassDao classDao;
/*
* @Param: [model]
* @Return: java.lang.String
* @Description: 转发到前台主页
*/
@RequestMapping("/front/student")
public String toFrontIndex(Model model) {
List<Notice> notices = noticeDao.queryAllNotice();
model.addAttribute("notices", notices);
return "front/student/index";
}
/*
* @Param: [session, model]
* @Return: java.lang.String
* @Description: 转发到前台选课页面。
*/
@RequestMapping({"/front/student/selectcourse"})
public String toSelectCourse(HttpSession session, Model model) {
List<Course> list = newList(courseDao.queryAllCourse());
model.addAttribute("courses", list);
List<Course> selectCourses = newList(studentDao.querySelectCourseByStudentID((String) session.getAttribute("LoginUser")));
model.addAttribute("selectCourses", selectCourses);
String msg = (String) session.getAttribute("msg");