IDEA+Java+JSP+Mysql+Tomcat实现Web学校教材管理系统
Java+JSP+Mysql实现Web学校教材管理系统,sql在sql文件夹下面;系统实现管理员登录系统,管理员对学校教材的增删改查。
·
目录
一、系统介绍
1.开发环境
开发工具:IDEA2018
JDK版本:Jdk1.8
Mysql版本:8.0.13
2.技术选型
Java+Jsp+Mysql
3.系统功能
1.登录系统;
2.管理员对学校教材的增删改查。
4.数据库文件
/*
Navicat Premium Data Transfer
Source Server : MYSQL
Source Server Type : MySQL
Source Server Version : 80013
Source Host : localhost:3306
Source Schema : jsp_teach_material
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 03/03/2022 17:04:24
*/
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 material
-- ----------------------------
DROP TABLE IF EXISTS `material`;
CREATE TABLE `material` (
`id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`author` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`publish` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of material
-- ----------------------------
INSERT INTO `material` VALUES (1001, '语文', '张三', '人民日报出版社', '900');
INSERT INTO `material` VALUES (1002, '数学', '李四', '人民日报出版社', '1000');
INSERT INTO `material` VALUES (1003, '英语', '王五', '人民日报出版社', '1500');
INSERT INTO `material` VALUES (1004, '赵六', '黄七', '人民日报出版社', '2000');
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.entity.Admin;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author: shuijianshiqing
* @date: 2022-03-01
* @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;
}
}
MaterialDaoImpl
package com.sjsq.dao.impl;
import com.sjsq.dao.MaterialDao;
import com.sjsq.entity.Material;
import com.sjsq.utils.DBUtil;
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: 2022-03-03
* @description:
*/
public class MaterialDaoImpl implements MaterialDao {
@Override
public List<Material> 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<Material> list = new ArrayList<>();
while (rs.next()) {
Material material = new Material();
material.setId(rs.getInt("id"));
material.setName(rs.getString("name"));
material.setAuthor(rs.getString("author"));
material.setPublish(rs.getString("publish"));
material.setNumberr(rs.getString("number"));
list.add(material);
}
return list;
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭链接,避免数据库连接过多
DBUtil.close(con, ps, rs);
}
return null;
}
@Override
public Material selectMaterial(Integer id) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.连接数据库
con = DBUtil.getConnection();
// 2.预编译
String sql = "select * from material where id = ?";
ps = con.prepareStatement(sql);
ps.setInt(1, id);
// 3.执行sql
rs = ps.executeQuery();
while (rs.next()) {
Material material = new Material();
material.setId(rs.getInt("id"));
material.setName(rs.getString("name"));
material.setAuthor(rs.getString("author"));
material.setPublish(rs.getString("publish"));
material.setNumberr(rs.getString("number"));
return material;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 关闭资源,避免出现异常
DBUtil.close(con, ps, rs);
}
return null;
}
@Override
public boolean addMaterial(Material material) {
String sql = "insert into material values (?,?,?,?,?)";
List<Object> list = new ArrayList<Object>();
list.add(material.getId());
list.add(material.getName());
list.add(material.getAuthor());
list.add(material.getPublish());
list.add(material.getNumber());
boolean flag = DBUtil.addUpdateDelete(sql, list.toArray());
if (flag) {
return true;
} else {
return false;
}
}
@Override
public boolean updateMaterial(Material material) {
String sql = "update material set name=?,author=?,publish=?,number=? where id=?";
List<Object> list = new ArrayList<Object>();
list.add(material.getName());
list.add(material.getAuthor());
list.add(material.getPublish());
list.add(material.getNumber());
// 注意id在最后面
list.add(material.getId());
boolean flag = DBUtil.addUpdateDelete(sql, list.toArray());
if (flag) {
return true;
} else {
return false;
}
}
@Override
public boolean deleteMaterial(Integer id) {
String sql = "delete from material 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;
}
}
}
material-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="material-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="author" id="author" placeholder="请输入教材作者">
</tr>
</div>
<div>
<tr>
<label>出版社名:</label>
<input type="text" name="publish" id="publish" placeholder="请输入出版社名">
</tr>
</div>
<div>
<tr>
<label>教材数量:</label>
<input type="text" name="number" id="number" 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;
// 教材编号和教材名称不能为空
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>
material-add-do.jsp
<%@ page import="com.sjsq.entity.Material" %>
<%@ page import="com.sjsq.service.MaterialService" %>
<%@ page import="com.sjsq.service.impl.MaterialServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>新增教材</title>
</head>
<body>
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding("UTF-8");
//获取teacher-add.jsp页面提交的账号和密码,注意传过来的是字符串需要进行转化为对应的类型
Integer id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String author = request.getParameter("author");
String publish = request.getParameter("publish");
String number = request.getParameter("number");
// 将信息保存到实体类中
Material material = new Material();
material.setId(id);
material.setName(name);
material.setAuthor(author);
material.setPublish(publish);
material.setNumberr(number);
System.out.println("添加的教材信息");
System.out.println(material);
// 将数据写入到数据库
MaterialService materialService = new MaterialServiceImpl();
boolean flag = materialService.addMaterial(material);
if(flag){
response.sendRedirect("main.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
</body>
</html>
material-update.jsp
<%@ page import="com.sjsq.entity.Material" %>
<%@ page import="com.sjsq.service.MaterialService" %>
<%@ page import="com.sjsq.service.impl.MaterialServiceImpl" %>
<%@ 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"));
MaterialService materialService = new MaterialServiceImpl();
Material material = materialService.selectMaterial(id);
%>
<div>
<a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
</br>
<form action="material-update-do.jsp" method="post" id="addForm">
<div>
<%-- 这里教职工号不能修改 --%>
<tr>
<label>教材编号:</label>
<input type="text" name="id" id="id" placeholder="请输入教材编号" value="<%=material.getId()%>" readonly="true">
</tr>
</div>
<div>
<tr>
<label>教材名称:</label>
<input type="text" name="name" id="name" placeholder="请输入教材名称" value="<%=material.getName()%>" autofocus="autofocus">
</tr>
</div>
<div>
<tr>
<label>教材作者:</label>
<input type="text" name="author" id="author" placeholder="请输入教材作者" value="<%=material.getAuthor()%>">
</tr>
</div>
<div>
<tr>
<label>出版社名:</label>
<input type="text" name="publish" id="publish" placeholder="请输入出版社名" value="<%=material.getPublish()%>">
</tr>
</div>
<div>
<tr>
<label>教材数量:</label>
<input type="text" name="number" id="number" placeholder="请输入教材数量" value="<%=material.getNumber()%>">
</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>
material-update-do.jsp
<%@ page import="com.sjsq.entity.Material" %>
<%@ page import="com.sjsq.service.MaterialService" %>
<%@ page import="com.sjsq.service.impl.MaterialServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改教材</title>
</head>
<body>
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding("UTF-8");
//获取teacher-update.jsp页面提交的账号和密码,注意传过来的是字符串需要进行转化为对应的类型
Integer id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String author = request.getParameter("author");
String publish = request.getParameter("publish");
String number = request.getParameter("number");
// 将信息保存到实体类中
Material material = new Material();
material.setId(id);
material.setName(name);
material.setAuthor(author);
material.setPublish(publish);
material.setNumberr(number);
System.out.println("修改的教材信息");
System.out.println(material);
// 将数据写入到数据库
MaterialService materialService = new MaterialServiceImpl();
boolean flag = materialService.updateMaterial(material);
if(flag){
response.sendRedirect("main.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
</body>
</html>
四、其他
1.更多系统
Java+JSP系统系列实现
Java+Servlet系统系列实现
Java+SSM系统系列实现
Java+SSH系统系列实现
Java+Springboot系统系列实现
Java+Springboot+H-ui+Maven实现营销管理系统
Java+Springboot+Bootstrap+Maven实现网上商城系统
Java+Springboot+Bootstrap+Maven实现景区旅游管理系统
1.更多JavaWeb系统请关注专栏。
2.更多JavaSwing系统请关注专栏。
2.源码下载
sql在sql文件夹下面
3.运行项目
4.备注
如有侵权请联系我删除。
5.支持博主
如果您觉得此文对您有帮助,请点赞加关注加收藏。祝您生活愉快!
更多推荐
已为社区贡献16条内容
所有评论(0)