基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)
作者:mmseoamin日期:2023-12-21

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

前台:登录、查看图书列表、借书、还书、导出借书信息

后台:图书管理、借阅审核、还书审核、用户管理、图书类别管理、借书数据统计图、导出图书信息

前台

后台:

技术框架

JSP Servlet MySQL JDBC Tomcat CSS JavaScript

基于javaweb+mysql的JSP+Servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat)

                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    ReturnBook returnBook = bookAdminService.findReturnById(Integer.parseInt(returnIdStr));
                                    returnBook.setBookAdmin(bookAdmin);
                                    returnBook.setReturntime(DateUtils.dateToString(new Date()));
                                    returnBook.setState(3);
                                    bookAdminService.modifyReturn(returnBook);
                                    int bookId = returnBook.getBook().getId();
                                    book = bookService.findBookById(bookId);
                                    book.setAbled(1);
                                    bookService.modifyBook(book);
                                    borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 4);
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 5);
                                    }
                                    if (borrow != null) {
                                        borrow.setState(3);
                                        borrow.setReturntime(DateUtils.dateToString(new Date()));
                                        bookAdminService.modifyBorrow(borrow);
                                        resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    } else {
                                        resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    }
                                    break;
                                //拒绝归还
                                case "disagree":
                                    returnIdStr = req.getParameter("returnId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    returnBook = bookAdminService.findReturnById(Integer.parseInt(returnIdStr));
                                    returnBook.setBookAdmin(bookAdmin);
                                    returnBook.setReturntime(DateUtils.dateToString(new Date()));
                                    returnBook.setState(5);
                                    bookAdminService.modifyReturn(returnBook);
                                    bookId = returnBook.getBook().getId();
                                    book = bookService.findBookById(bookId);
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 0);
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 4);
                                    }
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 5);
                                    }
                                    borrow.setState(5);
                    bookCaseId = req.getParameter("bookCaseId");
                    bookCase = bookAdminService.findBookCaseById(Integer.valueOf(bookCaseId));
                    book = new Book();
                    book.setId(Integer.valueOf(bookIdStr));
                    book.setName(name);
                    book.setAuthor(author);
                    book.setPublish(publish);
                    book.setPages(Integer.valueOf(pageStr));
                    book.setPrice(Float.valueOf(priceStr));
                    book.setBookCase(bookCase);
                    book.setAbled(1);
                    bookService.modifyBook(book);
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
                //添加图书
                case "preAdd":
                    bookCaseList = bookAdminService.findAllBookCase();
                    req.setAttribute("list",bookCaseList);
                    req.getRequestDispatcher("/book/book-add.jsp").forward(req,resp);
                    break;
                case "add":
                    name = req.getParameter("name");
                    author = req.getParameter("author");
                    publish = req.getParameter("publish");
                    pageStr = req.getParameter("pages");
                    priceStr = req.getParameter("price");
                    bookCaseId = req.getParameter("bookCaseId");
                    bookCase = bookAdminService.findBookCaseById(Integer.parseInt(bookCaseId));
                    book = new Book(name,Integer.parseInt(pageStr),Float.parseFloat(priceStr),publish,author,bookCase,1);
                    bookService.addBook(book);
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
                //删除图书
                case "delete":
                    bookIdStr = req.getParameter("bookId");
                    book = bookService.findBookById(Integer.parseInt(bookIdStr));
                    book.setBookCase(null);
                    bookService.deleteBookById(Integer.parseInt(bookIdStr));
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
            }
        }
    }
}
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        BookService bookService = new BookServiceImpl();
        BookAdminService bookAdminService = new BookAdminServiceImpl();
        Book book;
        String bookIdStr;
        List bookCaseList;
        String name;
        String author;
        String publish;
        String pageStr;
        String priceStr;
        String bookCaseId;
        BookCase bookCase;
        //查询图书
        if (method == null){
            resp.setCharacterEncoding("utf-8");
            pageStr = req.getParameter("page");
            String limitStr = req.getParameter("limit");
            List bookList = bookService.findAllBooks(Integer.valueOf(pageStr),Integer.valueOf(limitStr));
            BookVO bookVO = new BookVO();
            bookVO.setCode(0);
            bookVO.setMsg(null);
            bookVO.setCount(bookService.findBookCount());
            bookVO.setData(bookList);
            JSONObject jsonObject = JSONObject.fromObject(bookVO);
            System.out.println("jsonObject.toString():"+jsonObject.toString());
            resp.getWriter().write(jsonObject.toString());
        } else {
            switch (method) {
                //编辑图书
                case "preEdit":
                    bookIdStr = req.getParameter("bookId");
                    book = bookService.findBookById(Integer.valueOf(bookIdStr));
                    req.setAttribute("book",book);
                    bookCaseList = bookAdminService.findAllBookCase();
                    req.setAttribute("bookCaseList",bookCaseList);
                    req.getRequestDispatcher("/book/book-edit.jsp").forward(req,resp);
                    break;
                case "edit":
                    bookIdStr = req.getParameter("id");
                    name = req.getParameter("name");
                    author = req.getParameter("author");
                            break;
                        case "return":
                            List returnBookList = bookAdminService.findAllReturns();
                            ReturnBookVO returnBookVO = new ReturnBookVO();
                            count = bookAdminService.findReturnCount();
                            returnBookVO.setCode(0);
                            returnBookVO.setCount(count);
                            returnBookVO.setMsg(null);
                            returnBookVO.setData(returnBookList);
                            jsonObject = JSONObject.fromObject(returnBookVO);
                            resp.getWriter().write(jsonObject.toString());
                            break;
                    }
                    break;
                //借阅和归还的审核操作
                case "auditing":
                    switch (type) {
                        case "borrow":
                            switch (attitude) {
                                //同意借阅
                                case "agree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(1);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/borrow-manage.jsp");
                                    break;
                                //拒绝借阅
                                case "disagree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(2);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(1);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/borrow-manage.jsp");
                                    break;
                            }
                            break;
                        //归还图书操作
                        case "return":
                            switch (attitude) {
                                //同意归还
                                case "agree":
/**
 * @Description:读者操作功能类
 * @Param:
 * @return:
 */
public class ReaderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        ReaderService readerService = new ReaderServiceImpl();
        BookService bookService = new BookServiceImpl();
        BookAdminService bookAdminService = new BookAdminServiceImpl();
        String method = req.getParameter("method");
        int count = 0;
        Reader reader;
        String bookIdStr;
        String borrowId;
        //查询所有读者借阅图书信息
        if (method == null){
            reader = (Reader) session.getAttribute("reader");
            Constants.pageStr  = req.getParameter("page");
                            jsonObject = JSONObject.fromObject(returnBookVO);
                            resp.getWriter().write(jsonObject.toString());
                            break;
                    }
                    break;
                //借阅和归还的审核操作
                case "auditing":
                    switch (type) {
                        case "borrow":
                            switch (attitude) {
                                //同意借阅
                                case "agree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(1);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/borrow-manage.jsp");
                                    break;
                                //拒绝借阅
                                case "disagree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(2);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(1);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/borrow-manage.jsp");
                                    break;
                            }
                            break;
                        //归还图书操作
                        case "return":
                    priceStr = req.getParameter("price");
                    bookCaseId = req.getParameter("bookCaseId");
                    bookCase = bookAdminService.findBookCaseById(Integer.parseInt(bookCaseId));
                    book = new Book(name,Integer.parseInt(pageStr),Float.parseFloat(priceStr),publish,author,bookCase,1);
                    bookService.addBook(book);
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
                //删除图书
                case "delete":
                    bookIdStr = req.getParameter("bookId");
                    book = bookService.findBookById(Integer.parseInt(bookIdStr));
                    book.setBookCase(null);
                    bookService.deleteBookById(Integer.parseInt(bookIdStr));
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
            }
        }
    }
}
/**
 * @Description:用户登录功能类 
 * @Param:
 * @return:
 */
public class AccountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        String type = req.getParameter("type");
        AccountService accountService = new AccountServiceImpl();
        HttpSession session = req.getSession();
        switch (method){
            case "login":
/**
 * @Description:读者操作功能类
 * @Param:
 * @return:
 */
public class ReaderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        ReaderService readerService = new ReaderServiceImpl();
        BookService bookService = new BookServiceImpl();
        BookAdminService bookAdminService = new BookAdminServiceImpl();
        String method = req.getParameter("method");
        int count = 0;
        Reader reader;
        String bookIdStr;
        String borrowId;
        //查询所有读者借阅图书信息
        if (method == null){
            reader = (Reader) session.getAttribute("reader");
            Constants.pageStr  = req.getParameter("page");
                                    bookAdminService.modifyReturn(returnBook);
                                    int bookId = returnBook.getBook().getId();
                                    book = bookService.findBookById(bookId);
                                    book.setAbled(1);
                                    bookService.modifyBook(book);
                                    borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 4);
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 5);
                                    }
                                    if (borrow != null) {
                                        borrow.setState(3);
                                        borrow.setReturntime(DateUtils.dateToString(new Date()));
                                        bookAdminService.modifyBorrow(borrow);
                                        resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    } else {
                                        resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    }
                                    break;
                                //拒绝归还
                                case "disagree":
                                    returnIdStr = req.getParameter("returnId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    returnBook = bookAdminService.findReturnById(Integer.parseInt(returnIdStr));
                                    returnBook.setBookAdmin(bookAdmin);
                                    returnBook.setReturntime(DateUtils.dateToString(new Date()));
                                    returnBook.setState(5);
                                    bookAdminService.modifyReturn(returnBook);
                                    bookId = returnBook.getBook().getId();
                                    book = bookService.findBookById(bookId);
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 0);
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 4);
                                    }
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 5);
                                    }
                                    borrow.setState(5);
                                    borrow.setReturntime(DateUtils.dateToString(new Date()));
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    break;
                            }
                            break;
                    }
                    break;
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 5);
                                    }
                                    borrow.setState(5);
                                    borrow.setReturntime(DateUtils.dateToString(new Date()));
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    break;
                            }
                            break;
                    }
                    break;
                //显示图书数据操作
                case "getBookData":
                    switch (type) {
                        //显示成饼图
                        case "pie":
                            List bookPieDataList = bookAdminService.findBookDataForPie();
                            JSONArray jsonArray = JSONArray.fromObject(bookPieDataList);
                            resp.getWriter().write(jsonArray.toString());
                            break;
                        //显示成柱状图
                        case "bar":
                            BookBarData bookBarDataList = bookAdminService.findBookDataForBar();
                            jsonObject = JSONObject.fromObject(bookBarDataList);
                            resp.getWriter().write(jsonObject.toString());
                            break;
                    }
                    //导出数据操作
                case "exportDataInfo":
                    switch (type) {
                        //导出图书信息操作
                        case "book":
                            HSSFWorkbook hssfWorkbook = bookService.findWorkBook();
                            resp.setContentType("application/x-msdownload");
                            String fileName = "图书信息";
                            fileName = URLEncoder.encode(fileName, "UTF-8");
                            resp.setHeader("Content-Disposition", "attachment;filename*=utf-8'zh_cn'" + fileName + suffix);
                            OutputStream outputStream = resp.getOutputStream();
                            hssfWorkbook.write(outputStream);
                            outputStream.close();
                            break;
                        //导出图书借阅量数据
                borrow.setState(4);
                bookAdminService.modifyBorrow(borrow);
                reader = (Reader) session.getAttribute("reader");
                ReturnBook returnBook = new ReturnBook();
                returnBook.setBook(borrow.getBook());
                returnBook.setReader(reader);
                Date returnDate = new Date();
                returnBook.setReturntime(DateUtils.dateToString(returnDate));
                returnBook.setBookAdmin(null);
                returnBook.setState(4);
                bookAdminService.addReturnBook(returnBook);
                resp.sendRedirect(req.getContextPath()+"/reader/reader.jsp");
                break;
        }
    }
}
/**
 * @ClassName:BookServlet
 * @Description:图书控制层
 * @version:1.0
 */
public class BookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
                            borrowVO.setCount(count);
                            borrowVO.setCode(0);
                            borrowVO.setMsg(null);
                            jsonObject = JSONObject.fromObject(borrowVO);
                            resp.getWriter().write(jsonObject.toString());
                            break;
                        case "return":
                            List returnBookList = bookAdminService.findAllReturns();
                            ReturnBookVO returnBookVO = new ReturnBookVO();
                            count = bookAdminService.findReturnCount();
                            returnBookVO.setCode(0);
                            returnBookVO.setCount(count);
                            returnBookVO.setMsg(null);
                            returnBookVO.setData(returnBookList);
                            jsonObject = JSONObject.fromObject(returnBookVO);
                            resp.getWriter().write(jsonObject.toString());
                            break;
                    }
                    break;
                //借阅和归还的审核操作
                case "auditing":
                    switch (type) {
                        case "borrow":
                            switch (attitude) {
                                //同意借阅
                                case "agree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(1);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/borrow-manage.jsp");
                                    break;
                                //拒绝借阅
                                case "disagree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(2);
                                    book = bookService.findBookById(borrow.getBook().getId());
/**
 * @ClassName:BookServlet
 * @Description:图书控制层
 * @version:1.0
 */
public class BookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        BookService bookService = new BookServiceImpl();
        BookAdminService bookAdminService = new BookAdminServiceImpl();
        Book book;
        String bookIdStr;
        List bookCaseList;
        String name;
        String author;
        String publish;
        String pageStr;
        String priceStr;
        String bookCaseId;
        BookCase bookCase;
        //查询图书
        if (method == null){
            resp.setCharacterEncoding("utf-8");
            pageStr = req.getParameter("page");
            String limitStr = req.getParameter("limit");
            List bookList = bookService.findAllBooks(Integer.valueOf(pageStr),Integer.valueOf(limitStr));
            BookVO bookVO = new BookVO();
            bookVO.setCode(0);
            bookVO.setMsg(null);
            bookVO.setCount(bookService.findBookCount());
            bookVO.setData(bookList);
            JSONObject jsonObject = JSONObject.fromObject(bookVO);
                                    returnBook.setBookAdmin(bookAdmin);
                                    returnBook.setReturntime(DateUtils.dateToString(new Date()));
                                    returnBook.setState(3);
                                    bookAdminService.modifyReturn(returnBook);
                                    int bookId = returnBook.getBook().getId();
                                    book = bookService.findBookById(bookId);
                                    book.setAbled(1);
                                    bookService.modifyBook(book);
                                    borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 4);
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 5);
                                    }
                                    if (borrow != null) {
                                        borrow.setState(3);
                                        borrow.setReturntime(DateUtils.dateToString(new Date()));
                                        bookAdminService.modifyBorrow(borrow);
                                        resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    } else {
                                        resp.sendRedirect(req.getContextPath() + "/admin/return-manage.jsp");
                                    }
                                    break;
                                //拒绝归还
                                case "disagree":
                                    returnIdStr = req.getParameter("returnId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    returnBook = bookAdminService.findReturnById(Integer.parseInt(returnIdStr));
                                    returnBook.setBookAdmin(bookAdmin);
                                    returnBook.setReturntime(DateUtils.dateToString(new Date()));
                                    returnBook.setState(5);
                                    bookAdminService.modifyReturn(returnBook);
                                    bookId = returnBook.getBook().getId();
                                    book = bookService.findBookById(bookId);
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 0);
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 4);
                                    }
                                    if (borrow == null) {
                                        borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 5);
                                    }
                                    borrow.setState(5);
                        case "borrow":
                            switch (attitude) {
                                //同意借阅
                                case "agree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(1);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/borrow-manage.jsp");
                                    break;
                                //拒绝借阅
                                case "disagree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(2);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(1);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                                    resp.sendRedirect(req.getContextPath() + "/admin/borrow-manage.jsp");
                                    break;
                            }
                            break;
                        //归还图书操作
                        case "return":
                            switch (attitude) {
                                //同意归还
                                case "agree":
                                    returnIdStr = req.getParameter("returnId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    ReturnBook returnBook = bookAdminService.findReturnById(Integer.parseInt(returnIdStr));
                                    returnBook.setBookAdmin(bookAdmin);
                                    returnBook.setReturntime(DateUtils.dateToString(new Date()));
                                    returnBook.setState(3);
                                    bookAdminService.modifyReturn(returnBook);
                                    int bookId = returnBook.getBook().getId();
                                    book = bookService.findBookById(bookId);
                                    book.setAbled(1);
                                    bookService.modifyBook(book);
                                    borrow = readerService.findBorrowByIds(book.getId(), returnBook.getReader().getId(), 4);
                                    if (borrow == null) {
        String userAgent = req.getHeader("User-Agent");
        //根据方法名称判断
        if (method != null) {
            switch (method) {
                case "findAll":
                    //根据类型判断  borrow为借阅操作   return为还书操作
                    switch (type) {
                        case "borrow":
                            List borrowList = readerService.findAllBorrows();
                            int count = readerService.findBorrowsNum();
                            BorrowVO borrowVO = new BorrowVO();
                            borrowVO.setData(borrowList);
                            borrowVO.setCount(count);
                            borrowVO.setCode(0);
                            borrowVO.setMsg(null);
                            jsonObject = JSONObject.fromObject(borrowVO);
                            resp.getWriter().write(jsonObject.toString());
                            break;
                        case "return":
                            List returnBookList = bookAdminService.findAllReturns();
                            ReturnBookVO returnBookVO = new ReturnBookVO();
                            count = bookAdminService.findReturnCount();
                            returnBookVO.setCode(0);
                            returnBookVO.setCount(count);
                            returnBookVO.setMsg(null);
                            returnBookVO.setData(returnBookList);
                            jsonObject = JSONObject.fromObject(returnBookVO);
                            resp.getWriter().write(jsonObject.toString());
                            break;
                    }
                    break;
                //借阅和归还的审核操作
                case "auditing":
                    switch (type) {
                        case "borrow":
                            switch (attitude) {
                                //同意借阅
                                case "agree":
                                    borrowIdStr = req.getParameter("borrowId");
                                    bookAdmin = (BookAdmin) session.getAttribute("bookAdmin");
                                    borrow = readerService.findBorrowById(Integer.parseInt(borrowIdStr));
                                    borrow.setBookAdmin(bookAdmin);
                                    borrow.setState(1);
                                    book = bookService.findBookById(borrow.getBook().getId());
                                    book.setAbled(0);
                                    bookService.modifyBook(book);
                                    bookAdminService.modifyBorrow(borrow);
                    req.setAttribute("bookCaseList",bookCaseList);
                    req.getRequestDispatcher("/book/book-edit.jsp").forward(req,resp);
                    break;
                case "edit":
                    bookIdStr = req.getParameter("id");
                    name = req.getParameter("name");
                    author = req.getParameter("author");
                    publish = req.getParameter("publish");
                    pageStr = req.getParameter("pages");
                    priceStr = req.getParameter("price");
                    bookCaseId = req.getParameter("bookCaseId");
                    bookCase = bookAdminService.findBookCaseById(Integer.valueOf(bookCaseId));
                    book = new Book();
                    book.setId(Integer.valueOf(bookIdStr));
                    book.setName(name);
                    book.setAuthor(author);
                    book.setPublish(publish);
                    book.setPages(Integer.valueOf(pageStr));
                    book.setPrice(Float.valueOf(priceStr));
                    book.setBookCase(bookCase);
                    book.setAbled(1);
                    bookService.modifyBook(book);
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
                //添加图书
                case "preAdd":
                    bookCaseList = bookAdminService.findAllBookCase();
                    req.setAttribute("list",bookCaseList);
                    req.getRequestDispatcher("/book/book-add.jsp").forward(req,resp);
                    break;
                case "add":
                    name = req.getParameter("name");
                    author = req.getParameter("author");
                    publish = req.getParameter("publish");
                    pageStr = req.getParameter("pages");
                    priceStr = req.getParameter("price");
                    bookCaseId = req.getParameter("bookCaseId");
                    bookCase = bookAdminService.findBookCaseById(Integer.parseInt(bookCaseId));
                    book = new Book(name,Integer.parseInt(pageStr),Float.parseFloat(priceStr),publish,author,bookCase,1);
                    bookService.addBook(book);
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
                //删除图书
                case "delete":
                    bookIdStr = req.getParameter("bookId");
                    book = bookService.findBookById(Integer.parseInt(bookIdStr));
                    book.setBookCase(null);
                    bookService.deleteBookById(Integer.parseInt(bookIdStr));
                    resp.sendRedirect(req.getContextPath()+"/book/book-list.jsp");
                    break;
            }
        }
/**
 * @Description:读者操作功能类
 * @Param:
 * @return:
 */
public class ReaderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        ReaderService readerService = new ReaderServiceImpl();
        BookService bookService = new BookServiceImpl();
        BookAdminService bookAdminService = new BookAdminServiceImpl();
        String method = req.getParameter("method");
        int count = 0;
        Reader reader;
        String bookIdStr;
        String borrowId;
        //查询所有读者借阅图书信息
        if (method == null){
            reader = (Reader) session.getAttribute("reader");
            Constants.pageStr  = req.getParameter("page");
            Constants.limitStr = req.getParameter("limit");
            List borrowList = readerService.findBorrowsByReaderId(reader.getId(),Integer.valueOf(Constants.pageStr),Integer.valueOf(Constants.limitStr));
            count = readerService.findBorrowsCountByReaderId(reader.getId());
            BorrowVO borrowVO = new BorrowVO();
            borrowVO.setCode(0);
            borrowVO.setMsg(null);
            borrowVO.setCount(count);
            borrowVO.setData(borrowList);
            JSONObject jsonObject = JSONObject.fromObject(borrowVO);
            System.out.println("jsonObject.toString():"+jsonObject.toString());
            resp.getWriter().write(jsonObject.toString());
        } else switch (method) {
            //查询所有读者信息
            case "findAll":
                List readerList;
                Constants.pageStr = req.getParameter("page");
                Constants.limitStr = req.getParameter("limit");

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第1张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第2张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第3张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第4张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第5张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第6张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第7张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第8张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第9张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),第10张基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),第11张基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),第12张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第13张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第14张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),请添加图片描述,第15张

基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),第10张基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),第11张基于javaweb+mysql的jsp+servlet图书借阅管理系统(前台、后台)(java+jsp+servlet+javabean+mysql+tomcat),第12张