——————————DescriptionStart——————————
运行环境 Java≥8、MySQL≥5.7
开发工具 eclipse/idea/myeclipse/sts等均可配置运行
适用 课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot图书管理系统(java+html+springboot+thymeleaf+mysql+maven)
一、项目运行 环境配置:
Jdk1.8 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
HTML +Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 管理员: admin 123456 学生: 2088124 123456 2088125 123456 2088126 123456 2088127 123456 2088128 123456 2088129 123456 2088130 123456 2088131 123456 2088132 123456 2088133 123456 2088134 123456 2088135 123456 2088136 123456
——————————CodeStart——————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 } @PostMapping("/books/update") public String updateBooks (Book book,RedirectAttributes attributes) { adminBookService.updateBook(book); attributes.addFlashAttribute("message" , "修改书籍成功!!!" ); return "redirect:/admin/books" ; } @GetMapping("/books/{id}/delete") public String deleteBooks (@PathVariable Integer id,RedirectAttributes attributes) { adminBookService.deleteBookById(id); attributes.addFlashAttribute("message" ,"删除书籍成功" ); return "redirect:/admin/books" ; } } @Controller public class BookBorrowController { @Autowired private BorrowService borrowService; @Autowired private ReturnService returnService; @Autowired private UserService userService; @RequestMapping("/borrow") public String toMyBorrow (HttpSession session, Model model, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum) { User user = (User)session.getAttribute("user" );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 @Controller public class IndexController { @Autowired private UserService userService; @RequestMapping(value = {"/","/index"}) public String toIndex (HttpServletRequest request, HttpSession session, Model model) { User user = (User)session.getAttribute("user" ); User userById = userService.findUserById(user.getId()); model.addAttribute("userMessage" ,userById); return "index" ; } } public class LoginInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (request.getSession().getAttribute("user" ) == null ) { response.sendRedirect("/toLogin" ); return false ; } return true ; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 @GetMapping("/students/input") public String toAddStu (Model model) { model.addAttribute("students" ,new User()); return "admin/student-input" ; } @PostMapping("/students/add") public String addStu (@Valid User user, RedirectAttributes attributes) { System.out.println("前端传过来的user:" + user); if (adminUserService.getUserByUsername(user.getUsername())!=null ){ attributes.addFlashAttribute("message" ,"该用户名已被注册,请重试,建议使用学号" ); return "redirect:/admin/students/input" ; } else if (adminUserService.getUserByStuid(user.getStuid())!=null ){ attributes.addFlashAttribute("message" ,"请检查你的学号是否是你自己的" ); return "redirect:/admin/students/input" ; } adminUserService.insertUser(user); attributes.addFlashAttribute("message" ,"添加成功!!!" ); return "redirect:/admin/students" ; } @GetMapping("/students/{id}/update") public String toUpdateStu (@PathVariable Integer id,Model model) { System.out.println("toUpdateStu的id:" + id); User userById = adminUserService.getUserById(id); System.out.println("userById: " + userById); model.addAttribute("students" ,userById); return "admin/student-input" ; } @PostMapping("/students/update") public String updateStu (User user,RedirectAttributes attributes) { adminUserService.updateUser(user); attributes.addFlashAttribute("message" , "修改成功!!!" ); return "redirect:/admin/students" ; } @GetMapping("/students/{id}/delete") public String deleteBooks (@PathVariable Integer id,RedirectAttributes attributes) { adminUserService.deleteUserById(id); attributes.addFlashAttribute("message" ,"删除用户成功" ); return "redirect:/admin/books" ;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 @Controller public class BookBorrowController { @Autowired private BorrowService borrowService; @Autowired private ReturnService returnService; @Autowired private UserService userService; @RequestMapping("/borrow") public String toMyBorrow (HttpSession session, Model model, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum) { User user = (User)session.getAttribute("user" ); User userById = userService.findUserById(user.getId()); model.addAttribute("userMessage" ,userById); PageHelper.startPage(pageNum,6 ); List<Book> bookByBorrow = borrowService.findBookByBorrow(user.getStuid()); PageInfo<Book> bookPageInfo = new PageInfo<>(bookByBorrow); model.addAttribute("pageInfo" ,bookPageInfo); return "borrow" ; } @PostMapping("/borrow/search") public String searchBooks (@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, Model model, SearchBooks searchBooks) { PageHelper.startPage(pageNum,6 ); PageInfo<Book> booklist = borrowService.findBookList(pageNum,6 ,searchBooks); model.addAttribute("pageInfo" ,booklist); return "borrow :: bookList" ; } @GetMapping("/borrow/{bookId}/return") public String borrowBook (@PathVariable Integer bookId, RedirectAttributes attributes, HttpSession session) { User user = (User) session.getAttribute("user" ); System.out.println(bookId); Integer stuId = user.getStuid(); List<Book> bookByBorrow = borrowService.findBookByBorrow(stuId); returnService.deleteBorrow(bookId,stuId); returnService.updateReturnBook(bookId); attributes.addFlashAttribute("message" , "恭喜您,还书成功" ); return "redirect:/borrow" ; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 PageInfo<Book> bookPageInfo = new PageInfo<>(allBook); model.addAttribute("pageInfo" ,bookPageInfo); return "admin/book" ; } @PostMapping("/books/search") public String searchBooks (@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, Model model, SearchBooks searchBooks) { PageHelper.startPage(pageNum,6 ); PageInfo<Book> booklist = adminBookService.findBookList(pageNum,6 ,searchBooks); model.addAttribute("pageInfo" ,booklist); return "admin/book :: bookList" ; } @GetMapping("/books/input") public String toAddBooks (Model model) { model.addAttribute("books" ,new Book()); return "admin/book-input" ; } @PostMapping("/books/add") public String addBooks (@Valid Book book, RedirectAttributes attributes) { if (adminBookService.findBookByName(book.getName())!=null ){ attributes.addFlashAttribute("message" ,"该图书在管中已被添加:请添加其他书籍" ); return "redirect:/admin/books/input" ; } adminBookService.insertBook(book); attributes.addFlashAttribute("message" ,"添加书籍成功!!!" ); return "redirect:/admin/books" ; } @GetMapping("/books/{id}/update") public String toUpdateBooks (@PathVariable Integer id, Model model) { Book bookById = adminBookService.findBookById(id); model.addAttribute("books" ,bookById); return "admin/book-input" ; } @PostMapping("/books/update") public String updateBooks (Book book,RedirectAttributes attributes) { adminBookService.updateBook(book); attributes.addFlashAttribute("message" , "修改书籍成功!!!" ); return "redirect:/admin/books" ;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 @Controller public class BookController { @Autowired private BookService bookService; @Autowired private BorrowService borrowService; @Autowired private UserService userService; @RequestMapping("/books") public String toBookList (Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum, HttpSession session) { PageHelper.startPage(pageNum,6 ); List<Book> allBook = bookService.getAllBook(); PageInfo<Book> bookPageInfo = new PageInfo<>(allBook); model.addAttribute("pageInfo" ,bookPageInfo); User user = (User)session.getAttribute("user" ); User userById = userService.findUserById(user.getId()); model.addAttribute("userMessage" ,userById); return "book" ; } @PostMapping("/books/search") public String searchBooks (@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, Model model, SearchBooks searchBooks) { PageHelper.startPage(pageNum,6 ); PageInfo<Book> booklist = bookService.findBookList(pageNum,6 ,searchBooks); model.addAttribute("pageInfo" ,booklist); return "book :: bookList" ; } @GetMapping("/books/{bookId}/borrow") public String borrowBook (@PathVariable Integer bookId, RedirectAttributes attributes,HttpSession session) { User user = (User) session.getAttribute("user" ); Integer stuId = user.getStuid();
——————————PayStart——————————
项目链接: https://javayms.github.io?id=381422272105200bi https://javayms.pages.dev?id=381422272105200bi