IDEA+Java+Servlet+JSP+Mysql实现Web图书管理系统【建议收藏】


/*

Navicat Premium Data Transfer

Source Server : MySQL

Source Server Type : MySQL

Source Server Version : 80013

Source Host : 127.0.0.1:3306

Source Schema : servlet_library

Target Server Type : MySQL

Target Server Version : 80013

File Encoding : 65001

Date: 21/08/2021 22:14:51

*/

SET NAMES utf8mb4;

SET FOREIGN_KEY_CHECKS = 0;


– Table structure for book


DROP TABLE IF EXISTS book;

CREATE TABLE book (

id varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ‘书本ID’,

bookname varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘书本名称’,

author varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘书本作者’,

publisher varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘出版社’,

price int(11) NULL DEFAULT NULL COMMENT ‘书本价格’,

category varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘书本类目’,

store int(11) NULL DEFAULT NULL,

bookdesc varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

location varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

PRIMARY KEY (id) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = ‘书籍数据库’ ROW_FORMAT = Dynamic;


– Records of book


INSERT INTO book VALUES (‘000001’, ‘Java核心技术’, ‘凯 S. 霍斯特曼’, ‘机械工业出版社’, 130, ‘编程类’, 200, ‘《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。’, ‘3’);

INSERT INTO book VALUES (‘000003’, ‘算法竞赛入门经典’, ‘刘汝佳’, ‘清华大学出版社’, 50, ‘编程类’, 15, ‘《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。’, ‘3’);

INSERT INTO book VALUES (‘000004’, ‘概率论与数理统计’, ‘盛骤 谢式千 潘承毅’, ‘高等教育出版社’, 38, ‘数学类’, 15, ‘《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。’, ‘1’);

INSERT INTO book VALUES (‘000005’, ‘数据结构(C语言版)’, ‘严蔚敏 吴伟民’, ‘清华大学出版社’, 29, ‘编程类’, 8, ‘《JAVA核心技术》(第8版)是2011年电子工业出版社出版的图书,作者是昊斯特曼、Gary Cornell。本书针对JavaSE6平台进行了全面更新,囊括了Java平台标准版(JavaSE/J2SE)的全部基础知识,提供了大量完整且具有实际意义的应用实例。’, ‘3’);


– Table structure for iolog


DROP TABLE IF EXISTS iolog;

CREATE TABLE iolog (

bookid varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

readerid varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

service int(11) NULL DEFAULT NULL,

borrowtime varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

borrowday int(11) NULL DEFAULT NULL,

complete int(11) NULL DEFAULT NULL,

PRIMARY KEY (borrowtime) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;


– Records of iolog


INSERT INTO iolog VALUES (‘000001’, ‘1’, -1, ‘2021年08月21日 21时38分10秒’, 7, 1);

INSERT INTO iolog VALUES (‘000001’, ‘1’, 1, ‘2021年08月21日 21时38分20秒’, NULL, 1);


– Table structure for reader


DROP TABLE IF EXISTS reader;

CREATE TABLE reader (

username varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ‘读者用户名’,

password varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘读者密码’,

name varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘读者姓名’,

sex varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘读者性别’,

status int(11) NULL DEFAULT NULL COMMENT ‘读者状态(1.正常 -1.黑名单)’,

mail varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘读者邮箱’,

tel varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘读者电话’,

grade int(11) NULL DEFAULT -1 COMMENT ‘读者年级’,

classnum int(11) NULL DEFAULT -1 COMMENT ‘读者班级’,

PRIMARY KEY (username) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = ‘读者表’ ROW_FORMAT = Dynamic;


– Records of reader


INSERT INTO reader VALUES (‘1’, ‘123456’, ‘测试’, ‘测试’, 1, ‘测试’, ‘测试’, 1, 1);


– Table structure for tempadd


DROP TABLE IF EXISTS tempadd;

CREATE TABLE tempadd (

id varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,

bookname varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘书本名称’,

author varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘书本作者’,

publisher varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘出版社’,

price int(11) NULL DEFAULT NULL COMMENT ‘书本价格’,

category varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘书本类目’,

store int(11) NULL DEFAULT NULL,

bookdesc varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

location varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

PRIMARY KEY (id) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;


– Records of tempadd



– Table structure for user


DROP TABLE IF EXISTS user;

CREATE TABLE user (

user varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ‘用户名’,

password varchar(25) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘用户密码’,

name varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘用户真实姓名’,

sex varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘用户性别’,

department varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘用户部门’,

tel varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘用户电话’,

PRIMARY KEY (user) USING BTREE

) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;


– Records of user


INSERT INTO user VALUES (‘admin’, ‘admin’, ‘管理员’, ‘男’, ‘图书馆’, ‘12345678901’);

SET FOREIGN_KEY_CHECKS = 1;

5.工程截图


二、系统展示

=======

1.登录系统


2.主页面


3.图书列表


4.图书详情


5.编辑删除


6.添加图书


7.图书借阅


8.图书归还


9.借阅记录


10.用户管理


三、部分代码

=======

BookAction


package Action;

import Dao.BookDao;

import Entity.Book;

import Entity.User;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.ArrayList;

public class BookAction extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request, response);

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

request.setCharacterEncoding(“UTF-8”);

response.setCharacterEncoding(“UTF-8”);

String action = request.getParameter(“action”);

if (action.equals(“getall”)) {

this.getAll(request, response);

} else if (action.equals(“addtemp”)) {

this.addtemp(request, response);

} else if (action.equals(“gettemp”)) {

this.gettemp(request, response);

} else if (action.equals(“confirm”)) {

this.confirm(request, response);

} else if (action.equals(“querybookbyid”)) {

this.QueryBookById(request, response);

} else if (action.equals(“DeleteById”)) {

this.DeleteById(request, response);

} else if (action.equals(“EditDone”)) {

this.EditDone(request, response);

}

}

private void getAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

BookDao bdao = new BookDao();

ArrayList bookArrayList = bdao.getAllBook();

HttpSession session = request.getSession();

session.setAttribute(“allbooklist”, bookArrayList);

request.getRequestDispatcher(“/book-list.jsp”).forward(request, response);

}

private void addtemp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String next = request.getParameter(“over”);

BookDao bdao = new BookDao();

Book book = new Book();

if (!request.getParameter(“bookid”).equals(“”))

book.setId(request.getParameter(“bookid”));

if (!request.getParameter(“bookname”).equals(“”))

book.setName(request.getParameter(“bookname”));

if (!request.getParameter(“bookauthor”).equals(“”))

book.setAuthor(request.getParameter(“bookauthor”));

if (!request.getParameter(“bookpublisher”).equals(“”))

book.setPublisher(request.getParameter(“bookpublisher”));

if (!request.getParameter(“bookcategory”).equals(“”))

book.setCategory(request.getParameter(“bookcategory”));

if (!request.getParameter(“bookprice”).trim().equals(“”))

book.setPrice(Integer.parseInt(request.getParameter(“bookprice”)));

if (!request.getParameter(“bookstore”).trim().equals(“”))

book.setStore(Integer.parseInt(request.getParameter(“bookstore”)));

if (!request.getParameter(“booklocation”).equals(“”))

book.setLocation(request.getParameter(“booklocation”));

if (!request.getParameter(“bookdesc”).equals(“”))

book.setDesc(request.getParameter(“bookdesc”));

if (!request.getParameter(“bookid”).equals(“”))

bdao.addtemp(book);

if (next.equals(“0”))

request.getRequestDispatcher(“/add-book.jsp”).forward(request, response);

else

this.gettemp(request, response);

}

private void gettemp(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

BookDao bdao = new BookDao();

ArrayList addbooklist = bdao.getadd();

HttpSession session = request.getSession();

session.setAttribute(“addbooklist”, addbooklist);

request.getRequestDispatcher(“/add-confirm.jsp”).forward(request, response);

}

private void confirm(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

BookDao bdao = new BookDao();

bdao.confirm();

this.getAll(request, response);

}

private void QueryBookById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

BookDao bdao = new BookDao();

String id = request.getParameter(“id”);

String next = request.getParameter(“next”);

Book book = bdao.QueryBookById(id);

HttpSession session = request.getSession();

session.setAttribute(“resultbook”, book);

PrintWriter out = response.getWriter();

if (next.equals(“check”))

request.getRequestDispatcher(“/detail.jsp”).forward(request, response);

else if (next.equals(“edit”))

request.getRequestDispatcher(“/edit-book.jsp”).forward(request, response);

else if (next.equals(“borrowcheck”)) {

out.write(book.getName() + “||” + book.getAuthor() + “||” + book.getPublisher() + “||” + book.getRemain());

}

}

private void DeleteById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

BookDao bdao = new BookDao();

String id = request.getParameter(“id”);

bdao.DeleteById(id);

this.getAll(request, response);

}

private void EditDone(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

BookDao bdao = new BookDao();

Book book = new Book();

if (!request.getParameter(“id”).equals(“”))

book.setId(request.getParameter(“id”));

if (!request.getParameter(“name”).equals(“”))

book.setName(request.getParameter(“name”));

if (!request.getParameter(“author”).equals(“”))

book.setAuthor(request.getParameter(“author”));

if (!request.getParameter(“publisher”).equals(“”))

book.setPublisher(request.getParameter(“publisher”));

if (!request.getParameter(“category”).equals(“”))

book.setCategory(request.getParameter(“category”));

if (!request.getParameter(“price”).trim().equals(“”))

book.setPrice(Integer.parseInt(request.getParameter(“price”)));

if (!request.getParameter(“store”).trim().equals(“”))

book.setStore(Integer.parseInt(request.getParameter(“store”)));

if (!request.getParameter(“location”).equals(“”))

book.setLocation(request.getParameter(“location”));

if (!request.getParameter(“desc”).equals(“”))

book.setDesc(request.getParameter(“desc”));

if (!request.getParameter(“id”).equals(“”))

bdao.addtemp(book);

bdao.EditDone(book);

request.getRequestDispatcher(“BookAction?action=querybookbyid&id=<%=b.getId()%>&next=check”).forward(request, response);

}

}

IOAction


package Action;

import Dao.IODao;

import Entity.Log;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import java.io.IOException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;

import java.util.Date;

public class IOAction extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String action = request.getParameter(“action”);

if (action.equals(“borrow”)) {

this.borrow(request, response);

} else if (action.equals(“getlog”)) {

this.getlog(request, response);

} else if (action.equals(“return”)) {

this.ReturnBook(request, response);

}

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

this.doPost(request, response);

}

protected void borrow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

IODao ioDao = new IODao();

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy年MM月dd日 HH时mm分ss秒”);

Date date = new Date();

String time = sdf.format(date);

String readerid = request.getParameter(“readerid”);

String bookid = request.getParameter(“bookid”);

int borrowday = Integer.parseInt(request.getParameter(“borrowday”));

ioDao.borrow(bookid, readerid, time, borrowday);

this.getlog(request, response);

}

protected void getlog(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

IODao ioDao = new IODao();

ArrayList loglist = ioDao.getLogList();

HttpSession session = request.getSession();

session.setAttribute(“loglist”, loglist);

request.getRequestDispatcher(“/io-log.jsp”).forward(request, response);

}

protected void ReturnBook(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

IODao ioDao = new IODao();

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy年MM月dd日 HH时mm分ss秒”);

Date date = new Date();

String Returntime = sdf.format(date);

String bookid = request.getParameter(“bookid”);

String readerId = request.getParameter(“ReaderId”);

String borrowtime = request.getParameter(“borrowtime”);

ioDao.ReturnBook(bookid, readerId, borrowtime, Returntime);

this.getlog(request, response);

}

}

LoginAction


package Action;

import Dao.UserDao;

import Entity.User;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import java.io.IOException;

import java.io.PrintWriter;

public class LoginAction extends HttpServlet {

UserDao udao = new UserDao();

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String action = request.getParameter(“action”);

if (action.equals(“login”)) {

this.login(request, response);

} else if (action.equals(“logout”)) {

this.logout(request, response);

}

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doPost(request, response);

}

private void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String username = null;

String password = null;

PrintWriter out = response.getWriter();

HttpSession session = request.getSession();

username = request.getParameter(“username”);

password = request.getParameter(“password”);

User user = new User();

user.setUsername(username);

user.setPassword(password);

String result = udao.login(user);

if (result.equals(“true”)) {

session.setAttribute(“adminname”, user.getName());

request.getRequestDispatcher(“/main.jsp”).forward(request, response);

} else {

out.write(result);

}

}

private void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

HttpSession session = request.getSession();

session.setMaxInactiveInterval(1);

response.sendRedirect(“/index.jsp”);

}

}

ReaderAction


package Action;

/**

  • 读者管理

*/

import Dao.IODao;

import Dao.ReaderDao;

import Entity.Log;

import Entity.Reader;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.ArrayList;

public class ReaderAction extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String action = request.getParameter(“action”);

request.setCharacterEncoding(“UTF-8”);

response.setCharacterEncoding(“UTF-8”);

response.setContentType(“text/html; charset=utf-8”);

if (action.equals(“QueryReaderById”)) {

this.QueryReaderById(request, response);

} else if (action.equals(“GetBorrowListById”)) {

this.GetBorrowListById(request, response);

} else if (action.equals(“GetAllReader”)) {

this.GetAllReader(request, response);

} else if (action.equals(“SetBlackList”)) {

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
UTF-8");

response.setCharacterEncoding(“UTF-8”);

response.setContentType(“text/html; charset=utf-8”);

if (action.equals(“QueryReaderById”)) {

this.QueryReaderById(request, response);

} else if (action.equals(“GetBorrowListById”)) {

this.GetBorrowListById(request, response);

} else if (action.equals(“GetAllReader”)) {

this.GetAllReader(request, response);

} else if (action.equals(“SetBlackList”)) {

最后

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

[外链图片转存中…(img-HwaafEoT-1715457566290)]

[外链图片转存中…(img-TCYwnQg2-1715457566291)]

[外链图片转存中…(img-N19PEF3w-1715457566291)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点!不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!

如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值