Java教程

IDEA+Java+JSP+Mysql+Tomcat实现Web教师信息管理系统

本文主要是介绍IDEA+Java+JSP+Mysql+Tomcat实现Web教师信息管理系统,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目录

一、系统介绍

1.开发环境

2.技术选型

3.系统功能

4.数据库文件

5.工程截图

二、系统展示

1.登录系统

2.查询教师信息

3.添加教师信息

4.修改教师信息 

三、部分代码

AdminDaoImpl

TeacherDaoImpl

main.jsp

teacher-add.jsp

teacher-delete.jsp

teacher-update.jsp

四、其他

1.更多系统

Java+JSP系统系列实现

 Java+Servlet系统系列实现

Java+SSM系统系列实现

Java+SSH系统系列实现

Java+Springboot系统系列实现

2.源码下载

3.运行项目

4.备注

5.支持博主


一、系统介绍

1.开发环境

开发工具:IDEA2018

JDK版本:Jdk1.8

Mysql版本:8.0.13

2.技术选型

Java+Jsp+Mysql

3.系统功能

1.管理员登录系统;

2.管理员查询教师信息;

3.管理员新增教师信息;

4.管理员修改教师信息;

5.管理员删除教师信息;

4.数据库文件

/*
 Navicat Premium Data Transfer

 Source Server         : MYSQL
 Source Server Type    : MySQL
 Source Server Version : 80013
 Source Host           : localhost:3306
 Source Schema         : jsp_teacher_management

 Target Server Type    : MySQL
 Target Server Version : 80013
 File Encoding         : 65001

 Date: 14/01/2022 15:36:09
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin`  (
  `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of admin
-- ----------------------------
INSERT INTO `admin` VALUES ('admin', 'admin');

-- ----------------------------
-- Table structure for teacher
-- ----------------------------
DROP TABLE IF EXISTS `teacher`;
CREATE TABLE `teacher`  (
  `id` int(11) NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  `sex` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  `subject` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  `salary` double NULL DEFAULT NULL,
  `workTime` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1004 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of teacher
-- ----------------------------
INSERT INTO `teacher` VALUES (1001, '王老师', '男', '语文', 30000, '2022-01-01');
INSERT INTO `teacher` VALUES (1002, '张老师', '女', '英语', 30000, '2022-01-01');
INSERT INTO `teacher` VALUES (1003, '黄老师', '男', '数学', 30000, '2022-01-14');
INSERT INTO `teacher` VALUES (1004, '杨老师', '女', '英语', 30000, '2022-01-14');
INSERT INTO `teacher` VALUES (1005, '吴老师', '女', '音乐', 30000, '2022-01-14');

SET FOREIGN_KEY_CHECKS = 1;

5.工程截图

二、系统展示

1.登录系统

2.查询教师信息

3.添加教师信息

4.修改教师信息 

三、部分代码

AdminDaoImpl

package com.sjsq.dao.impl;

import com.sjsq.dao.AdminDao;
import com.sjsq.utils.DBUtil;
import com.sjsq.vo.Admin;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author: shuijianshiqing
 * @date: 2021-12-31
 * @description: 登录系统实现
 */
public class AdminDaoImpl implements AdminDao {

    /**
     * 登录系统
     * @param admin
     * @return
     */
    @Override
    public Admin login(Admin admin) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            // 1.获取数据库连接
            con = DBUtil.getConnection();
            // 2.写sql
            String sql = "select * from admin where username = ? and password = ?";
            // 3.预编译
            ps = con.prepareStatement(sql);
            // 4.设置值
            ps.setObject(1, admin.getUsername());
            ps.setObject(2, admin.getPassword());
            rs = ps.executeQuery();
            Admin adminLogin = null;
            if (rs.next()) {
                adminLogin = new Admin();
                // 从数据库中获取值到实体类的setter方法中
                adminLogin.setUsername(rs.getString("username"));
                adminLogin.setPassword(rs.getString("password"));

                // 返回的是你查询出来的完整的对象
                return adminLogin;

            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            // 关闭资源,避免出现异常
            DBUtil.close(con, ps, rs);
        }
        return null;
    }

}


TeacherDaoImpl

package com.sjsq.dao.impl;

import com.sjsq.dao.TeacherDao;
import com.sjsq.utils.DBUtil;
import com.sjsq.vo.Teacher;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: shuijianshiqing
 * @date: 2021-12-31
 * @description:
 */
public class TeacherDaoImpl implements TeacherDao {

    /**
     * 查询教师信息
     * @param sql
     * @param arr
     * @return
     */
    @Override
    public List<Teacher> selectAll(String sql, Object[] arr) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            // 1.连接数据库
            con = DBUtil.getConnection();
            // 2.预编译
            ps = con.prepareStatement(sql);
            if (arr != null) {
                for (int i = 0; i < arr.length; i++) {
                    // 传入sql的参数,向上转型,某个栏位的查询
                    ps.setObject(i + 1, arr[i]);
                }
            }
            // 3.执行sql
            rs = ps.executeQuery();
            // 4.保存查询出来的数据到list
            List<Teacher> list = new ArrayList<>();
            while (rs.next()) {

                Teacher teacher = new Teacher();

                teacher.setId(rs.getInt("id"));
                teacher.setName(rs.getString("name"));
                teacher.setSex(rs.getString("sex"));
                teacher.setSubject(rs.getString("subject"));
                teacher.setSalary(rs.getDouble("salary"));
                teacher.setWorkTime(rs.getString("workTime"));

                list.add(teacher);
            }
            return list;

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 关闭链接,避免数据库连接过多
            DBUtil.close(con, ps, rs);
        }
        return null;
    }

    /**
     * 根据教职工号查询教师信息
     * @param id
     * @return
     */
    @Override
    public Teacher selectTeacher(Integer id) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            // 1.连接数据库
            con = DBUtil.getConnection();
            // 2.预编译
            String sql = "select * from Teacher where id = ?";
            ps = con.prepareStatement(sql);
            ps.setInt(1,id);
            // 3.执行sql
            rs = ps.executeQuery();
            while (rs.next()){
                Teacher teacher = new Teacher();

                teacher.setId(rs.getInt("id"));
                teacher.setName(rs.getString("name"));
                teacher.setSex(rs.getString("sex"));
                teacher.setSubject(rs.getString("subject"));
                teacher.setSalary(rs.getDouble("salary"));
                teacher.setWorkTime(rs.getString("workTime"));

                return teacher;
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            // 关闭资源,避免出现异常
            DBUtil.close(con,ps,rs);
        }
        return null;
    }

    /**
     * 新增教师信息
     * @param teacher
     * @return
     */
    @Override
    public boolean addTeacher(Teacher teacher) {
        String sql = "insert into teacher values (?,?,?,?,?,?)";
        List<Object> list = new ArrayList<Object>();

        list.add(teacher.getId());
        list.add(teacher.getName());
        list.add(teacher.getSex());
        list.add(teacher.getSubject());
        list.add(teacher.getSalary());
        list.add(teacher.getWorkTime());

        boolean flag = DBUtil.addUpdateDelete(sql,list.toArray());
        if(flag){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 更新教师信息
     * @param teacher
     * @return
     */
    @Override
    public boolean updateTeacher(Teacher teacher) {
        String sql = "update teacher set name=?,sex=?,subject=?,salary=?,workTime=? where id=?";
        List<Object> list = new ArrayList<Object>();


        list.add(teacher.getName());
        list.add(teacher.getSex());
        list.add(teacher.getSubject());
        list.add(teacher.getSalary());
        list.add(teacher.getWorkTime());
        // 注意id在最后面
        list.add(teacher.getId());

        boolean flag = DBUtil.addUpdateDelete(sql,list.toArray());
        if(flag){
            return true;
        }else {
            return false;
        }
    }


    /**
     * 删除教师信息
     * @param id
     * @return
     */
    @Override
    public boolean deleteTeacher(Integer id) {
        String sql = "delete from teacher where id=?";
        List<Object> list = new ArrayList<Object>();

        list.add(id);

        boolean flag = DBUtil.addUpdateDelete(sql,list.toArray());
        if(flag){
            return true;
        }else {
            return false;
        }
    }
}


main.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ page import="com.sjsq.service.TeacherService" %>
<%@ page import="com.sjsq.service.impl.TeacherServiceImpl" %>
<%@ page import="com.sjsq.vo.Teacher" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>查看教师</title>
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <style type="text/css">


    </style>
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<%
    // 设置获取注册时的编码为UTF-8
    request.setCharacterEncoding("UTF-8");

    TeacherService studentService = new TeacherServiceImpl();
    // 定义一个学生类
    Teacher teacher = new Teacher();

    // 获取上一个页面传过来的值
    if (request.getParameter("id") != null && request.getParameter("id") != "") {
        Integer id = Integer.parseInt(request.getParameter("id"));
        teacher.setId(id);
    }

    // 获取所有教师
    List<Teacher> list = studentService.selectAll(teacher);
%>
<h1>教师列表</h1>
<hr/>
<div id="before">
    <form action="main.jsp" method="post">
        请输入教职工号:<input type="text" name="id" placeholder="输入教职工号搜索">
        <input type="submit" value="查询"/>
    </form>
</div>
<br>
<table align="center" border="1" cellspacing="0">
    <tr bgcolor="#6495ed";>
        <th>教职工号</th>
        <th>教师姓名</th>
        <th>教师性别</th>
        <th>教学科目</th>
        <th>教师工资</th>
        <th>入职时间</th>
        <th colspan="2">操作</th>
    </tr>
    <%
        for (int i = 0; i < list.size(); i++) {
            Teacher t = list.get(i);
    %>
    <tr id="content">
        <td><%=t.getId()%>
        </td>
        <td><%=t.getName()%>
        </td>
        <td><%=t.getSex()%>
        </td>
        <td><%=t.getSubject()%>
        </td>
        <td><%=t.getSalary()%>
        </td>
        <td><%=t.getWorkTime()%>
        </td>
        <td>
            <a href="teacher-update.jsp?id=<%=t.getId()%>">修改</a>
            <a href="teacher-delete.jsp?id=<%=t.getId()%>">删除</a>
        </td>
    </tr>
    <%
        }
    %>
</table>

<br>
<table align="center">
    <tr>
        <td><a href="teacher-add.jsp">新增教师</a></td>
    </tr>
</table>

</body>
<%-- 底部 --%>
<jsp:include page="bottom.jsp"/>
</html>


teacher-add.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增教师</title>
    <link rel="stylesheet" type="text/css" href="css/common.css">
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>

<h1>新增教师</h1>
<hr/>

<div id="before">
    <a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
</br>

<form action="teacher-add-do.jsp" method="post" name="addForm">
    <div>
        <tr>
            <label>教职工号:</label>
            <input type="text" name="id" id="id" placeholder="请输入教职工号">
        </tr>
    </div>
    <div>
        <tr>
            <label>教师姓名:</label>
            <input type="text" name="name" id="name" placeholder="请输入教师姓名">
        </tr>
    </div>
    <div>
        <tr>
            <label>教师性别:</label>
            <input type="text" name="sex" id="sex" placeholder="请输入教师性别">
        </tr>
    </div>
    <div>
        <tr>
            <label>教学科目:</label>
            <input type="text" name="subject" id="subject" placeholder="请输入教学科目">
        </tr>
    </div>
    <div>
        <tr>
            <label>教师工资:</label>
            <input type="text" name="salary" id="salary" placeholder="请输入教师工资">
        </tr>

    </div>
    <div>
        <tr>
            <label>工作时间:</label>
            <input type="text" name="workTime" id="workTime" placeholder="请输入工作时间">
        </tr>

    </div>

    <br>
    <div id="submit">
        <tr>
            <button type="submit" onclick="return checkForm()">添加</button>
            <button type="reset">重置</button>

        </tr>
    </div>
</form>

<script type="text/javascript">
    function checkForm() {
        var id = addForm.id.value;
        var name = addForm.name.value;
        var salary = addForm.salary.value;

        // 教职工号和姓名不能为空
        if (id == "" || id == null) {
            alert("请输入教职工号");
            addForm.id.focus();
            return false;
        } else if (name == "" || name == null) {
            alert("请输入教师姓名");
            addForm.name.focus();
            return false;
        }
        else if (salary == "" || salary == null) {
            alert("请输入教工资");
            addForm.salary.focus();
            return false;
        }
        return true;
    }
</script>

<%-- 底部 --%>
<jsp:include page="bottom.jsp"/>
</body>
</html>


teacher-delete.jsp

<%@ page import="com.sjsq.service.TeacherService" %>
<%@ page import="com.sjsq.service.impl.TeacherServiceImpl" %>
<%@ page import="com.sjsq.vo.Teacher" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>删除教师</title>
</head>
<body>
<%
    // 设置获取注册时的编码为UTF-8
    request.setCharacterEncoding("UTF-8");

    //获取main.jsp页面的id
    Integer id = Integer.parseInt(request.getParameter("id"));

    // 删除学生
    TeacherService TeacherService = new TeacherServiceImpl();
    Teacher teacher = new Teacher();
    teacher = TeacherService.selectTeacher(id);
    System.out.println("删除的教师信息");
    System.out.println(teacher);

    boolean flag = TeacherService.deleteTeacher(id);

    if (flag) {
        response.sendRedirect("main.jsp");
    } else {
        response.sendRedirect("error.jsp");
    }
%>
</body>
</html>


teacher-update.jsp

<%@ page import="com.sjsq.service.TeacherService" %>
<%@ page import="com.sjsq.service.impl.TeacherServiceImpl" %>
<%@ page import="com.sjsq.vo.Teacher" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改教师</title>
    <link rel="stylesheet" type="text/css" href="css/common.css">
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>

<h1>修改教师</h1>
<hr/>

<%
    //获取main.jsp页面的id
    Integer id = Integer.parseInt(request.getParameter("id"));
    TeacherService teacherService = new TeacherServiceImpl();
    Teacher teacher = teacherService.selectTeacher(id);
%>

<div>
    <a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
</br>

<form action="teacher-update-do.jsp" method="post" id="addForm">

    <div>
        <%-- 这里教职工号不能修改 --%>
        <tr>
            <label>教职工号:</label>
            <input type="text" name="id" id="id" placeholder="请输入教职工号" value="<%=teacher.getId()%>" readonly="true">
        </tr>
    </div>
    <div>
        <tr>
            <label>教师姓名:</label>
            <input type="text" name="name" id="name" placeholder="请输入教师姓名" value="<%=teacher.getName()%>" autofocus="autofocus">
        </tr>
    </div>
    <div>
        <tr>
            <label>教师性别:</label>
            <input type="text" name="sex" id="sex" placeholder="请输入教师性别" value="<%=teacher.getSex()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>教学科目:</label>
            <input type="text" name="subject" id="subject" placeholder="请输入教学科目" value="<%=teacher.getSubject()%>">
        </tr>
    </div>
    <div>
        <tr>
            <label>教师工资:</label>
            <input type="text" name="salary" id="salary" placeholder="请输入教师工资" value="<%=teacher.getSalary()%>">
        </tr>

    </div>
    <div>
        <tr>
            <label>工作时间:</label>
            <input type="text" name="workTime" id="workTime" placeholder="请输入工作时间" value="<%=teacher.getWorkTime()%>">
        </tr>

    </div>

    <br>
    <div id="submit">
        <tr>
            <button type="submit" onclick="return checkForm()">修改</button>
            <button type="reset">重置</button>

        </tr>
    </div>
</form>



<script type="text/javascript">
    function checkForm() {
        var id = addForm.id.value;
        var name = addForm.name.value;

        // 教职工号和姓名不能为空
        if (id == "" || id == null) {
            alert("请输入教职工号");
            addForm.id.focus();
            return false;
        } else if (name == "" || name == null) {
            alert("请输入教师姓名");
            addForm.name.focus();
            return false;
        }
        return true;
    }
</script>

<%-- 底部 --%>
<jsp:include page="bottom.jsp"/>
</body>
</html>

四、其他

1.更多系统

Java+JSP系统系列实现

Java+JSP实现学生图书管理系统

Java+JSP实现学生信息管理系统

Java+JSP实现用户信息管理系统

 Java+Servlet系统系列实现

Java+Servlet+JSP实现航空订票系统

Java+Servlet+JSP实现新闻发布系统

Java+Servlet+JSP学生宿舍管理系统

Java+Servlet+JSP实现图书管理系统

Java+Servlet+JSP实现停车场管理系统

Java+Servlet+JSP实现房屋租赁管理系统

Java+Servlet+JSP实现学生信息管理系统

Java+Servlet+JSP实现学生选课管理系统

Java+Servlet+JSPl实现学生选课签到系统

Java+Servlet+JSP实现宠物诊所管理系统

Java+Servlet+JSP实现学生成绩管理系统-1

Java+Servlet+JSP实现学生成绩管理系统-2

Java+SSM系统系列实现

J​​​ava+SSM+JSP实现网上考试系统

Java+SSM+JSP实现宠物商城系统

Java+SSM+JSP实现超市管理系统

Java+SSM+JSP实现学生成绩管理系统

Java+SSM+JSP实现学生信息管理系统

Java+SSM+JSP+Maven实现网上书城系统

Java+SSM+JSP+Maven实现学校教务管理系统

Java+SSH系统系列实现

Java+SSH+JSP实现在线考试系统

Java+SSH+JSP实现医院在线挂号系统

Java+Springboot系统系列实现

Java+Springboot+H-ui+Maven实现营销管理系统

Java+Springboot+Bootstrap+Maven实现网上商城系统

Java+Springboot+Bootstrap+Maven实现景区旅游管理系统

1.更多JavaWeb系统请关注专栏。

https://blog.csdn.net/helongqiang/category_10020130.htmlhttps://blog.csdn.net/helongqiang/category_10020130.html

2.更多JavaSwing系统请关注专栏。

https://blog.csdn.net/helongqiang/category_6229101.htmlhttps://blog.csdn.net/helongqiang/category_6229101.html

2.源码下载

sql在sql文件夹下面

Java+JSP+Mysql实现Web教师信息管理系统

3.运行项目

IDEA如何导入JavaWeb项目超详细视频教程

如果您想详细了解代码的实现,已经有一个录好的相关视频可能会帮助到您!具体的实现方式都差不多,只是实体类有些差别!

视频传送门在下面

手把手教你实现Web图书管理系统视频教程

4.备注

如有侵权请联系我删除。

5.支持博主

如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!

这篇关于IDEA+Java+JSP+Mysql+Tomcat实现Web教师信息管理系统的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!