基于javaweb+jsp的教务管理系统(JavaWeb MySQL JSP Bootstrap Servlet SSM SpringBoot)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript Bootstrap.
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架或SpringBoot…均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、课程模块、学生模块、教师模块的增删改查管理
/**
* 增加教师
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("teacherAdd")
public void add(HttpServletResponse response, HttpServletRequest request) throws IOException {
Teacher vo = new Teacher();
//取出页面传进来的参数
vo.setTeacherName(Util.decode(request, "teacherName"));
vo.setTeacherSex(Util.decode(request, "teacherSex"));
vo.setTeacherDegree(Util.decode(request, "teacherDegree"));
vo.setTeacherPotition(Util.decode(request, "teacherPotition"));
vo.setTeacherCollege(Util.decode(request, "teacherCollege"));
vo.setTeacherPhone(Util.decode(request, "teacherPhone"));
div>
body>
<script>
function searchList() {
window.location.href = "courseList?searchColumn="+document.getElementById("searchColumn").value+"&keyword=" + document.getElementById("search_keyword").value;
}
script>
html>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = Util.decode(request, "searchColumn");
String keyword = Util.decode(request, "keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = userService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = Util.decode(request, "pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = Util.decode(request, "searchColumn");
String keyword = Util.decode(request, "keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = studentService.list(params);
request.getSession().setAttribute("list", map.get("list"));
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
//移除错误提示
session.removeAttribute("alert_msg");
//登录拦截
String uri = request.getRequestURI().substring(request.getRequestURI().lastIndexOf("/"));
String[] access = new String[]{"login", "logout", "register", ".css", ".js", ".png", ".jpg", "validationCode"};
for (String action : access) {
if (uri.toLowerCase().contains(action.toLowerCase())) {
return true;
}
}
if (session.getAttribute("loginUser") == null) {
}
}
package com.demo.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.text.SimpleDateFormat;
/**
* 该方法为通用的工具类,放置一些共用的方法
*/
public class Util {
/**
* 获取系统当前时间并格式化为字符串
*
* @return
*/
public static String getTime() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis());
public void add(HttpServletResponse response, HttpServletRequest request) throws IOException {
Course vo = new Course();
//取出页面传进来的参数
vo.setCourseName(Util.decode(request, "courseName"));
vo.setCourseTime(Util.decode(request, "courseTime"));
vo.setCourseRoom(Util.decode(request, "courseRoom"));
vo.setCourseWeek(Util.decode(request, "courseWeek"));
vo.setCourseCollege(Util.decode(request, "courseCollege"));
vo.setCourseScore(Util.decode(request, "courseScore"));
vo.setCourseText(Util.decode(request, "courseText"));
//调用Service层的增加(insert)方法
courseService.insert(vo);
this.redirectList(request, response);
INSERT INTO `t_notice`
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test ='id != null'>`id`,if>
<if test ='noticeName != null'>`notice_name`,if>
<if test ='noticeText != null'>`notice_text`,if>
<if test ='noticeType != null'>`notice_type`,if>
<if test ='createDate != null'>`create_date`if>
trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test ='id != null'>#{id},if>
<if test ='noticeName != null'>#{noticeName},if>
<if test ='noticeText != null'>#{noticeText},if>
<if test ='noticeType != null'>#{noticeType},if>
<if test ='createDate != null'>#{createDate}if>
trim>
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping
public class TeacherController {
response.sendRedirect("course_list.jsp");
}
}
package com.demo.controller;
import com.demo.util.Util;
import com.demo.service.TeacherService;
import com.demo.vo.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
response.sendRedirect("student_list.jsp");
}
}
package com.demo.controller;
import com.demo.util.Util;
import com.demo.service.CourseService;
import com.demo.vo.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
* @param request
* @throws IOException
*/
@RequestMapping({"courseGet", "courseEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = Util.decode(request, "id");//取出主键id
Course vo = courseService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("course_" + to + ".jsp");
}
/**
* 根据条件查询课程的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping
public class NoticeController {
@Autowired
private NoticeService noticeService;
/**
* 增加公告
*
* @param response
* @param request
#{id}
foreach>
delete>
<update id="doUpdate" parameterType="com.demo.vo.Student">
UPDATE `t_student`
<set>
<if test ='id != null'>`id` = #{id},if>
<if test ='studentName != null'>`student_name` = #{studentName},if>
<if test ='studentAge != null'>`student_age` = #{studentAge},if>
<if test ='studentSex != null'>`student_sex` = #{studentSex},if>
<if test ='studentNumber != null'>`student_number` = #{studentNumber},if>
<if test ='studentClass != null'>`student_class` = #{studentClass},if>
<if test ='studentPhone != null'>`student_phone` = #{studentPhone},if>
select>
mapper>
DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.demo.dao.CourseMapper">
<resultMap id="BaseResultMap" type="com.demo.vo.Course" >
<result column="id" property="id" />
<result column="course_name" property="courseName" />
<result column="course_time" property="courseTime" />
<result column="course_room" property="courseRoom" />
<result column="course_week" property="courseWeek" />
<result column="course_college" property="courseCollege" />
<result column="course_score" property="courseScore" />
<result column="course_text" property="courseText" />
resultMap>
<sql id="Base_Column_List">
`id`,`course_name`,`course_time`,`course_room`,`course_week`,`course_college`,`course_score`,`course_text`
sql>
/**
* 列表页面的显示对象
*
* @param
*/
public class PageBean<T> {
private List<T> list;//根据条件查询出来的list集合
private int totalRecord;//根据条件查询出来的数量
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public int getTotalRecord() {
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = Util.decode(request, "searchColumn");
String keyword = Util.decode(request, "keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword);//查询的关键字
Map<String, Object> map = teacherService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = Util.decode(request, "pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) teacherService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
vo.setStudentSex(Util.decode(request, "studentSex"));
vo.setStudentNumber(Util.decode(request, "studentNumber"));
vo.setStudentClass(Util.decode(request, "studentClass"));
vo.setStudentPhone(Util.decode(request, "studentPhone"));
vo.setStudentText(Util.decode(request, "studentText"));
studentService.update(vo);
this.redirectList(request, response);
}
/**
* 获取学生的详细信息(详情页面与编辑页面要显示该学生的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"studentGet", "studentEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = Util.decode(request, "id");//取出主键id
Student vo = studentService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("student_" + to + ".jsp");
}