IDEA+Java+SSM+JSP+Mysql实现Web图书管理系统

number varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

name varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

keyword varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

remark varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

createtime date NULL DEFAULT NULL,

PRIMARY KEY (id) USING BTREE,

INDEX number(number) USING BTREE

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


– Records of booktype


INSERT INTO booktype VALUES (5, ‘bt001’, ‘军事’, NULL, NULL, NULL);

INSERT INTO booktype VALUES (6, ‘bt002’, ‘经济’, NULL, NULL, NULL);

INSERT INTO booktype VALUES (8, ‘bt003’, ‘语言’, NULL, NULL, NULL);

INSERT INTO booktype VALUES (9, ‘bt004’, ‘文学’, NULL, NULL, NULL);

INSERT INTO booktype VALUES (10, ‘bt005’, ‘艺术’, NULL, NULL, NULL);

INSERT INTO booktype VALUES (11, ‘bt006’, ‘历史’, NULL, NULL, NULL);

INSERT INTO booktype VALUES (22, ‘bt007’, ‘综合’, NULL, NULL, NULL);

INSERT INTO booktype VALUES (23, ‘bt008’, ‘地理’, NULL, NULL, NULL);


– Table structure for reader


DROP TABLE IF EXISTS reader;

CREATE TABLE reader (

id bigint(4) NOT NULL AUTO_INCREMENT,

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

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

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

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

workunit varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

homeaddress varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

tel varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

email varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

createtime date NULL DEFAULT NULL,

remark varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

PRIMARY KEY (id) USING BTREE

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


– Records of reader


INSERT INTO reader VALUES (1, ‘r001’, ‘张三’, ‘rt002’, ‘女’, ‘广州’, ‘广州’, ‘15626277129’, ‘913772015@qq.com’, NULL, NULL);

INSERT INTO reader VALUES (2, ‘r002’, ‘李四’, ‘rt001’, ‘男’, NULL, NULL, NULL, NULL, NULL, NULL);

INSERT INTO reader VALUES (5, ‘r003’, ‘王五’, ‘rt001’, ‘男’, ‘市委’, ‘湖南长沙’, ‘12345678911’, ‘wangwu@qq.com’, ‘2021-12-11’, NULL);


– Table structure for reader_account


DROP TABLE IF EXISTS reader_account;

CREATE TABLE reader_account (

id bigint(4) NOT NULL,

username varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

password varchar(8) 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 reader_account


INSERT INTO reader_account VALUES (1, ‘r001’, ‘r001’);

INSERT INTO reader_account VALUES (2, ‘r002’, ‘r002’);

INSERT INTO reader_account VALUES (3, ‘r003’, ‘r003’);


– Table structure for readertype


DROP TABLE IF EXISTS readertype;

CREATE TABLE readertype (

id bigint(4) NOT NULL AUTO_INCREMENT,

number varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

name varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

borrownumber varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘借书数量’,

borrowterm varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ‘借书期限’,

remark varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

createtime date NULL DEFAULT NULL,

PRIMARY KEY (id) USING BTREE

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


– Records of readertype


INSERT INTO readertype VALUES (1, ‘rt001’, ‘一级读者’, ‘8’, ‘30’, NULL, NULL);

INSERT INTO readertype VALUES (2, ‘rt002’, ‘二级读者’, ‘10’, ‘60’, NULL, NULL);


– Table structure for record


DROP TABLE IF EXISTS record;

CREATE TABLE record (

id bigint(4) NOT NULL AUTO_INCREMENT,

readernumber varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

booknumber varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

borrowdate date NULL DEFAULT NULL,

returndate date NULL DEFAULT NULL,

remark varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,

PRIMARY KEY (id) USING BTREE,

INDEX reader(readernumber) USING BTREE,

INDEX book(booknumber) USING BTREE

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


– Records of record


INSERT INTO record VALUES (8, ‘r002’, ‘b001’, ‘2018-06-27’, ‘2018-06-27’, NULL);

INSERT INTO record VALUES (9, ‘r001’, ‘b001’, ‘2018-06-27’, ‘2018-06-27’, NULL);

INSERT INTO record VALUES (10, ‘r001’, ‘b001’, ‘2018-06-27’, ‘2018-06-27’, NULL);

INSERT INTO record VALUES (11, ‘r001’, ‘b001’, ‘2021-12-11’, ‘2021-12-11’, ‘’);

INSERT INTO record VALUES (12, ‘r001’, ‘b001’, ‘2021-12-11’, ‘2021-12-11’, NULL);

INSERT INTO record VALUES (14, ‘r001’, ‘b001’, ‘2021-12-11’, ‘2021-12-11’, ‘r001’);

INSERT INTO record VALUES (15, ‘r001’, ‘b004’, ‘2021-12-11’, ‘2021-12-11’, ‘r001’);

INSERT INTO record VALUES (16, ‘r001’, ‘b005’, ‘2021-12-11’, ‘2021-12-11’, ‘r001’);

SET FOREIGN_KEY_CHECKS = 1;

二、系统展示

======

1.登录系统


2.用户-借阅书籍


3.管理员-图书管理


4.管理员-图书类型管理


5.管理员-读者管理


6.管理员-读者类型管理


7.管理员-借阅记录查看


三、部分代码

======

BookController


package com.sjsq.controller;

import com.sjsq.pojo.Book;

import com.sjsq.pojo.BookType;

import com.sjsq.pojo.Record;

import com.sjsq.service.BookService;

import com.sjsq.service.ReaderService;

import com.sjsq.service.RecordService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.math.BigDecimal;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.List;

@Controller

public class BookController {

@Autowired

private BookService bookService;

@Autowired

private RecordService recordService;

@Autowired

private ReaderService readerService;

@RequestMapping(“/book/list”)

public String bookList(Model model, HttpServletRequest request) throws Exception {

request.setCharacterEncoding(“UTF-8”);

String name = request.getParameter(“bookName”);

String type = request.getParameter(“bookType”);

String press = request.getParameter(“bookPress”);

List bookList = bookService.queryBook(name, type, press);

List bookTypeList = bookService.queryAllBookType();

List bookNumberList = bookService.queryBookNumber();

List readerNumberList = readerService.queryReaderNumber();

model.addAttribute(“books”, bookList);

request.getSession().setAttribute(“bookTypes”, bookTypeList);

request.getSession().setAttribute(“bookNumbers”, bookNumberList);

request.getSession().setAttribute(“readerNumbers”, readerNumberList);

model.addAttribute(“bookName”, name);

model.addAttribute(“bookType”, type);

return “admin_books”;

}

@RequestMapping(“/book/listreader”)

public String bookListReader(Model model, HttpServletRequest request) throws Exception {

request.setCharacterEncoding(“UTF-8”);

String name = request.getParameter(“bookName”);

String type = request.getParameter(“bookType”);

String press = request.getParameter(“bookPress”);

List bookList = bookService.queryBook(name, type, press);

List bookTypeList = bookService.queryAllBookType();

List bookNumberList = bookService.queryBookNumber();

List readerNumberList = readerService.queryReaderNumber();

model.addAttribute(“books”, bookList);

request.getSession().setAttribute(“bookTypes”, bookTypeList);

request.getSession().setAttribute(“bookNumbers”, bookNumberList);

request.getSession().setAttribute(“readerNumbers”, readerNumberList);

model.addAttribute(“bookName”, name);

model.addAttribute(“bookType”, type);

return “reader_books”;

}

@RequestMapping(“/book/edit.action”)

public @ResponseBody

Book bookEdit(String number) {

Book book = bookService.queryBookByNumber(number);

return book;

}

@RequestMapping(“/book/update.action”)

public @ResponseBody

String bookUpdate(Book book) {

bookService.updateBookById(book);

return “OK”;

}

/用book实体接收不了前端传过来的变量,只能一个一个收/

@RequestMapping(“/book/add.action”)

public @ResponseBody

String bookAdd(HttpServletRequest request) throws Exception {

Date publicationdate = null;

Integer pagecount = null;

BigDecimal price = null;

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

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

String author = request.getParameter(“anthor”);

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

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

String publicationdateStr = request.getParameter(“publicationdate”);

String priceStr = request.getParameter(“price”);

String pagecountStr = request.getParameter(“pagecount”);

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

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);

String createtimeStr = sdf.format(new Date());

Date createtime = sdf.parse(createtimeStr);

if (publicationdateStr != “”) {

publicationdate = sdf.parse(publicationdateStr);

}

if (pagecountStr != “”) {

pagecount = Integer.parseInt(pagecountStr);

}

if (priceStr != “”) {

price = new BigDecimal(priceStr);

}

Book book = new Book(type, name, number, author, press, publicationdate,

price, pagecount, createtime, 0, remark);

bookService.addBook(book);

return “OK”;

}

@RequestMapping(“/book/delete.action”)

public @ResponseBody

String bookDelete(String number) {

bookService.deleteBookByNumber(number);

return “OK”;

}

@RequestMapping(“/book/lent.action”)

public @ResponseBody

String lentBook(HttpServletRequest request) throws Exception {

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

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

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

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);

String borrowtimeStr = sdf.format(new Date());

Date borrowtime = sdf.parse(borrowtimeStr);

Record record = new Record();

record.setReaderNumber(readerNumber);

record.setBookNumber(bookNumber);

record.setBorrowDate(borrowtime);

record.setRemark(remark);

bookService.updateBookStatusByNumber(1, bookNumber);

recordService.addRecord(record);

return “OK”;

}

@RequestMapping(“/book/return.action”)

public @ResponseBody

String returnBook(HttpServletRequest request) throws Exception {

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

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);

String returntimeStr = sdf.format(new Date());

Date returntime = sdf.parse(returntimeStr);

bookService.updateBookStatusByNumber(0, bookNumber);

recordService.setReturnDate(bookNumber, returntime);

return “OK”;

}

@RequestMapping(“/record/list”)

public String recordList(Model model, HttpServletRequest request) throws Exception {

request.setCharacterEncoding(“UTF-8”);

List recordList = recordService.queryAllFullRecord();

model.addAttribute(“records”, recordList);

return “record”;

}

}

BookTypeController


package com.sjsq.controller;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.sjsq.pojo.BookType;

import com.sjsq.service.BookService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.List;

@Controller

public class BookTypeController {

@Autowired

private BookService bookService;

@RequestMapping(“/booktype/list”)

public String bookTypeList(Model model, HttpServletRequest request) throws Exception {

request.setCharacterEncoding(“UTF-8”);

List bookTypeList = bookService.queryAllBookType();

ObjectMapper om = new ObjectMapper();

String jsonStr = om.writeValueAsString(bookTypeList);

System.out.println(jsonStr);

model.addAttribute(“bookTypes”, bookTypeList); //前端foreach标签好像解析不了json

model.addAttribute(“bookTypesJSON”, jsonStr);

return “admin_booktype”;

}

@RequestMapping(“/booktype/edit.action”)

public @ResponseBody

BookType bookTypeEdit(String number) {

BookType booktype = bookService.queryBookTypeByNumber(number);

return booktype;

}

@RequestMapping(“/booktype/update.action”)

public @ResponseBody

String bookTypeUpdate(BookType bookType) {

bookService.updateBookTypeById(bookType);

return “OK”;

}

@RequestMapping(“/booktype/add.action”)

public @ResponseBody

String bookTypeAdd(HttpServletRequest request) throws Exception {

/*private int id;

private String number;

private String name;

private String keyword;

private String remark;*/

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

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

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

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);

String createtimeStr = sdf.format(new Date());

Date createtime = sdf.parse(createtimeStr);

BookType bookType = new BookType(number, name, remark, createtime);

bookService.addBookType(bookType);

return “OK”;

}

@RequestMapping(“/booktype/delete.action”)

public @ResponseBody

String bookTypeDelete(String number) {

bookService.deleteBookTypeByNumber(number);

return “OK”;

}

}

LoginController


package com.sjsq.controller;

import com.sjsq.pojo.Admin;

import com.sjsq.pojo.ReaderAccount;

import com.sjsq.service.LoginService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.util.HashMap;

@Controller

public class LoginController {

@Autowired

private LoginService loginService;

@RequestMapping(value = {“/”, “/login.html”})

public String toLogin(HttpServletRequest request) {

return “index”;

}

@RequestMapping(“/logout.html”)

public String logout(HttpServletRequest request) {

return “redirect:/login.html”;

}

@RequestMapping(“/logincheck”)

public @ResponseBody

Object loginCheck(HttpServletRequest request) {

HashMap<String, String> res = new HashMap<String, String>();

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

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

Admin admin = loginService.queryAdminByUsernameAndPasswd(username, password);

ReaderAccount readerAccount = loginService.queryReaderAccountByUsernameAndPasswd(username, password);

if (admin != null && readerAccount == null) {

res.put(“stateCode”, “1”);

request.getSession().setAttribute(“admin”, admin);

} else if (admin == null && readerAccount != null) {

res.put(“stateCode”, “2”);

request.getSession().setAttribute(“readerAccount”, readerAccount);

} else {

res.put(“stateCode”, “0”);

}

return res;

}

@RequestMapping(“/admin_main.html”)

public String toAdminMain(HttpServletResponse response) {

return “admin_main”;

}

@RequestMapping(“/reader_main.html”)

public String toReaderMain(HttpServletResponse response) {

return “reader_main”;

}

}

ReaderTypeController


package com.sjsq.controller;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.sjsq.pojo.ReaderType;

import com.sjsq.service.ReaderService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.List;

@Controller

public class ReaderTypeController {

@Autowired

private ReaderService readerService;

@RequestMapping(“/readertype/list”)

public String readerTypeList(Model model, HttpServletRequest request) throws Exception {

request.setCharacterEncoding(“UTF-8”);

List readerTypeList = readerService.queryAllReaderType();

ObjectMapper om = new ObjectMapper();

String jsonStr = om.writeValueAsString(readerTypeList);

System.out.println(jsonStr);

model.addAttribute(“readerTypes”, readerTypeList); //前端foreach标签好像解析不了json

model.addAttribute(“readerTypesJSON”, jsonStr);

return “admin_readertype”;

}

@RequestMapping(“/readertype/edit.action”)

public @ResponseBody

ReaderType readerTypeEdit(String number) {

ReaderType readertype = readerService.queryReaderTypeByNumber(number);

return readertype;

}

@RequestMapping(“/readertype/update.action”)

public @ResponseBody

String readerTypeUpdate(ReaderType readerType) {

readerService.updateReaderTypeById(readerType);

return “OK”;

}

@RequestMapping(“/readertype/add.action”)

public @ResponseBody

String readerTypeAdd(HttpServletRequest request) throws Exception {

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

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

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

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

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

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd”);

String createtimeStr = sdf.format(new Date());

Date createtime = sdf.parse(createtimeStr);

ReaderType readerType = new ReaderType(number, name, borrownumber, borrowterm, remark, createtime);

readerService.addReaderType(readerType);

return “OK”;

}

@RequestMapping(“/readertype/delete.action”)

public @ResponseBody

String readerTypeDelete(String number) {

readerService.deleteReaderTypeByNumber(number);

return “OK”;

}

}

四、其他

====

1.更多系统


Java+JSP系统系列实现

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

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

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

Java+Servlet系统系列实现

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

  • 18
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值