@Override public List<?> extractData(ResultSet rs) { List<BCopies> bcopies = new ArrayList<BCopies>(); BookDAO bdao = new BookDAO(conn); try { while (rs.next()) { BCopies a = new BCopies(); Book book = new Book(); Branch branch = new Branch(); book.setBookId(rs.getInt("bookId")); try { book = bdao.getBook(book.getBookId()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } branch.setBranchId(rs.getInt("branchId")); branch.setBranchName(rs.getString("branchName")); a.setNoofCopies(rs.getInt("noOfCopies")); a.setBook(book); a.setBranch(branch); bcopies.add(a); } } catch (SQLException e) { e.printStackTrace(); } return bcopies; }
/** *******************图书借阅********************** */ private void bookborrow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 查询读者信息 readerForm.setBarcode(request.getParameter("barcode")); ReaderForm reader = (ReaderForm) readerDAO.queryM(readerForm); request.setAttribute("readerinfo", reader); // 查询读者的借阅信息 request.setAttribute("borrowinfo", borrowDAO.borrowinfo(request.getParameter("barcode"))); // 完成借阅 String f = request.getParameter("f"); String key = request.getParameter("inputkey"); if (key != null && !key.equals("")) { String operator = request.getParameter("operator"); BookForm bookForm = bookDAO.queryB(f, key); if (bookForm != null) { int ret = borrowDAO.insertBorrow(reader, bookDAO.queryB(f, key), operator); if (ret == 1) { request.setAttribute("bar", request.getParameter("barcode")); request.getRequestDispatcher("bookBorrow_ok.jsp").forward(request, response); } else { request.setAttribute("error", "添加借阅信息失败!"); request.getRequestDispatcher("error.jsp").forward(request, response); } } else { request.setAttribute("error", "没有该图书!"); request.getRequestDispatcher("error.jsp").forward(request, response); } } else { request.getRequestDispatcher("bookBorrow.jsp").forward(request, response); } }
@RequestMapping( value = "/deleteBook", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json") public List<Book> deleteBook(@RequestBody Book book) { bookdao.deleteBook(book); return bookdao.getAllBooks(1, 5); }
@RequestMapping( value = "/getBooksCount", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json") public int getBooksCount() { return bookdao.getBooksCount(); }
@RequestMapping( value = "/editBook", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json") public void editBook(@RequestBody List<Book> books) { for (Book book : books) bookdao.updateBook(book); }
/*Admin Book*/ @RequestMapping( value = "/getBooks/{pageNo}/{pageSize}", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json") public List<Book> getBooks(@PathVariable int pageNo, @PathVariable int pageSize) { return bookdao.getAllBooks(pageNo, pageSize); }
@RequestMapping( value = "/getBooksByName/{searchString}/{pageNo}/{pageSize}", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json") public List<Book> getBooksByName( @PathVariable String searchString, @PathVariable int pageNo, @PathVariable int pageSize) { return bookdao.getBooksByName(searchString, pageNo, pageSize); }
/** * The doPost method of the servlet. <br> * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); // System.out.println("test"); // Get book ID from request header String id = request.getParameter("bookID"); BookDAO bookDao = new BookDAO(); try { Book book = bookDao.getBookById(id); if (book != null) { // Send it to next jsp to handle it request.setAttribute("book", book); request.getRequestDispatcher("/updateBook.jsp").forward(request, response); } } catch (DocumentException e) { e.printStackTrace(); } }
@Override public List extractData(ResultSet rs) throws Exception { List<Genre> genres = new ArrayList<Genre>(); BookDAO bdao = new BookDAO(getConnection()); while (rs.next()) { Genre g = new Genre(); g.setGenreId(rs.getInt("genre_id")); g.setGenreName(rs.getString("genre_name")); @SuppressWarnings("unchecked") List<Book> books = (List<Book>) bdao.readFirstLevel( "select * from tbl_book where bookId In" + "(select bookId from tbl_book_genres where genreId=?)", new Object[] {rs.getInt("genreId")}); genres.add(g); } return genres; }
@Override public List<Author> extractData(ResultSet rs) throws Exception { List<Author> authors = new ArrayList<Author>(); BookDAO bDao = new BookDAO(getConnection()); while (rs.next()) { Author a = new Author(); a.setAuthorId(rs.getInt("authorId")); a.setAuthorName(rs.getString("authorName")); @SuppressWarnings("unchecked") List<Book> books = (List<Book>) bDao.readFirstLevel( "select * from tbl_book where bookId In" + "(select bookId from tbl_book_authors where authorId=?)", new Object[] {rs.getInt("authorId")}); a.setBooks(books); authors.add(a); } return authors; }