图书管理系统 毕业设计( 三 )

books = bookMapper.findAllBooks();Integer sum = 0;for (Book b :books) {sum += b.getNum();}model.addAttribute("views",views);System.out.println("sum:"+sum);model.addAttribute("total",sum);model.addAttribute("books",books);model.addAttribute("num",books.size());model.addAttribute("isadmin",session.getAttribute("isadmin"));return "index";}
3.3 管理员模块 3.3.1 用户管理
图3-5 用户管理界面
用户管理代码
删除
@RequestMapping("/user_delete")public String user_delete(@RequestParam("id") String id){System.out.println(id);userMapper.deleteUserById(id);userBorrowMapper.deleteUserBorrowByUserId(id);return "redirect:user";}
更新
图3-6 用户更新页面
代码
@RequestMapping("/update_user")public String update_user(User user){System.out.println("update_user:"+user.toString());userMapper.updateUserById(user);return "redirect:user";}
3.3.2 书本管理
书本管理主页
图3-7 书籍管理界面

图书管理系统 毕业设计

文章插图
代码
@RequestMapping("/book")public String book(Model model,HttpSession session){Param param = paramMapper.findParamByName("views");if(param!=null){paramMapper.updateParamById(param.getId());}else{paramMapper.addParam(new Param(UUID.randomUUID().toString().replace("-",""),"views",1));}Integer views = paramMapper.findParamByName("views").getNum();List books = bookMapper.findAllBooks();Integer sum = 0;for (Book b :books) {sum += b.getNum();}System.out.println("sum:"+sum);model.addAttribute("total",sum);model.addAttribute("books",books);model.addAttribute("num",books.size());model.addAttribute("views",views);model.addAttribute("username",session.getAttribute("username"));model.addAttribute("isadmin",session.getAttribute("isadmin"));return "book";}
删除
@RequestMapping("/book_delete")public String book_delete(@RequestParam("id") String id){System.out.println(id);Book book = bookMapper.findBookById(id);Integer booknum = book.getNum();if (booknum>1){bookMapper.updateBookNumById(id);}else{userBorrowMapper.deleteUserBorrowByBookId(id);bookMapper.deleteBookById(id);}return "redirect:book";}
更新
图3-8 书本更新页面
代码
@RequestMapping("/book_update")public String book_update(Book book,Model model){bookMapper.updateBookById(book);return "redirect:book";}
添加
图3-9 书本添加页面
代码
@RequestMapping("/add_book")public String add_book(Book book){book.setId(UUID.randomUUID().toString().replace("-",""));bookMapper.addBook(book);return "redirect:book";}
搜索
图3-10 书籍管理书本搜索结果页面
代码
@RequestMapping("/book_search")public String book_search(String keywords,Model model,HttpSession session){System.out.println("keywords:"+keywords);List books = bookMapper.findBooksByKeywords(keywords);Integer sum = 0;for (Book b :books) {sum+=b.getNum();}model.addAttribute("books",books);model.addAttribute("num",books.size());model.addAttribute("sum",sum);model.addAttribute("isadmin",session.getAttribute("isadmin"));return "search_book_page";}
3.4 借阅归还模块 3.4.1 借阅
图3-11 书本详情页面
借阅代码
@RequestMapping("/borrow")public String borrow(@RequestParam("id") String id,Model model,HttpSession session){String uid = (String)session.getAttribute("id");String bid = id;Book book = bookMapper.findBookById(id);UserBorrow userBorrow = userBorrowMapper.findUserBorrowByUidAndBid(uid,id);if (userBorrow==null){String tid = UUID.randomUUID().toString().replace("-","");userBorrow = new UserBorrow(tid,uid,bid,1,new Date(System.currentTimeMillis()),null);userBorrowMapper.addUserBorrow(userBorrow);}else{userBorrowMapper.updateUserBorrowByIdBorrow(userBorrow.getId(),1);}UserBorrow userBorrow1 = userBorrowMapper.findUserBorrowByUidAndBid(uid,bid);model.addAttribute("book",book);model.addAttribute("username",session.getAttribute("username"));model.addAttribute("isBorrow",userBorrow1.getIsValid());return "book_detail";}