当前位置:   article > 正文

Java项目:图书管理系统(java+SpringBoot+jpa+html+swagger+maven+mysql)_java图书管理系统源代码idea mysql html

java图书管理系统源代码idea mysql html

源码获取:博客首页 "资源" 里下载!

项目介绍

该项目比较界面简单大方,功能简洁,只有三张表,适合java初学者或者课程设计;
主要功能包括:
首页轮播图
图书管理:图书列表、图书上架;
借阅管理:搜索图书、借阅图书、归还图书;
读者管理:读者列表、读者添加;

用户中心:个人信息、用户管理、添加管理员;

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目

6.数据库:MySql 5.7版本;

技术栈

1. 后端:springboot+jpa+mybatis+springsecurity+swagger+

2. 前端:html+javaex

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2.将book-manager导入到开发工具中(idea/eclipse)均可
- idea:直接open打开源码文件夹,记住是pom文件所在的目录
- eclipse: 直接导入- 选择已存在导入maven项目
- 检查maven是否配置好,建议使用阿里云加速,这样等待时间比较短
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080 登录
5. 管理员用户名:admin 密码:123

 

 

 

 

 

 

图书类别处理控制层:

  1. /**
  2. * @description: 图书类别处理
  3. */
  4. @Controller
  5. @RequestMapping("/admin/ch/category")
  6. public class CategoryController {
  7. //注入
  8. @Autowired
  9. private LibraryCategoryService libraryCategoryService;
  10. /**
  11. * 添加 图书类目
  12. *
  13. * @param category 图书类目信息
  14. * @param session 添加人
  15. * @return url
  16. * @author hiseico
  17. */
  18. @RequestMapping(value = "/addCategory", method = RequestMethod.POST)
  19. public String addCategory(TbCategory category, HttpSession session, Model model) {
  20. List<TbCategory> categoryList = libraryCategoryService.getCategoryAll();
  21. boolean is = false;
  22. for (TbCategory tbCategory : categoryList) {
  23. if (category.getCatname().equals(tbCategory.getCatname())) {
  24. is = true;
  25. break;
  26. }
  27. }
  28. if (!is) {
  29. // 添加 数据到 数据库,并 修改 父类目
  30. libraryCategoryService.addBookCategory(category, session);
  31. } else {
  32. model.addAttribute("errorMsg", "类目已经存在");
  33. return "errorMsg";
  34. }
  35. return "redirect:/admin/ch/loan_BookClassify.action";
  36. }
  37. /**
  38. * 删除类目信息
  39. *
  40. * @param id
  41. * @return
  42. */
  43. @RequestMapping(value = "/delCategory", method = RequestMethod.GET)
  44. public String delCategory(int id) {
  45. // 通过 类目id 删除数据
  46. libraryCategoryService.delBookCategoryById(id);
  47. return "redirect:/admin/ch/loan_BookClassify.action";
  48. }
  49. /**
  50. * 修改 类目关系
  51. *
  52. * @param category
  53. * @return
  54. */
  55. @RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
  56. public String updateCategory(TbCategory category) {
  57. return "redirect:/admin/ch/loan_BookClassify.action";
  58. }
  59. @RequestMapping("/toUpdatePage")
  60. @ResponseBody
  61. public TbCategory toUpdatePage(int id) {
  62. return libraryCategoryService.getCategoryById(id);
  63. }
  64. }

图书操作控制层: 

  1. /**
  2. * @description: 图书操作
  3. */
  4. @Controller
  5. @RequestMapping("/admin/ch")
  6. public class LibraryController {
  7. //注入
  8. @Autowired
  9. private LibraryService libraryService;
  10. /**
  11. * 修改图书信息
  12. *
  13. * @param uploadFile 上传图片
  14. * @param library 图书信息
  15. * @return
  16. */
  17. @RequestMapping(value = "/updateBook", method = RequestMethod.POST)
  18. public String updateBook(MultipartFile uploadFile, TbLibrary library, HttpServletRequest request) {
  19. try {
  20. libraryService.updateOrSaveLibrary(uploadFile, library,request);
  21. } catch (IOException e) {
  22. e.printStackTrace();
  23. }
  24. return "redirect:/admin/ch/loan_bookList.action";
  25. }
  26. /**
  27. * 添加图书
  28. *
  29. * @param uploadFile 上传图片
  30. * @param library 图书信息
  31. * @return
  32. */
  33. @RequestMapping(value = "/addBook", method = RequestMethod.POST)
  34. public String addBook(MultipartFile uploadFile, TbLibrary library, HttpSession session,HttpServletRequest request) {
  35. ActiveAdmin activeAdmin = (ActiveAdmin) session.getAttribute("activeAdmin");
  36. library.setManagerId(activeAdmin.getUserid());
  37. try {
  38. libraryService.updateOrSaveLibrary(uploadFile, library,request);
  39. } catch (IOException e) {
  40. e.printStackTrace();
  41. }
  42. return "redirect:/admin/ch/loan_bookList.action";
  43. }
  44. /**
  45. * 根据 图书id 删除 图书
  46. *
  47. * @param id 图书id
  48. * @return
  49. */
  50. @RequestMapping("/delBookById")
  51. public String delBook(int id) {
  52. libraryService.delBookById(id);
  53. return "redirect:/admin/ch/loan_bookList.action";
  54. }
  55. }

前台页面列表显示处理:

  1. /**
  2. * @description: 前台页面列表显示处理
  3. */
  4. @Controller
  5. @RequestMapping("/user/ch")
  6. public class UserBookController {
  7. // 注入
  8. @Autowired
  9. private LibraryService libraryService;
  10. @Autowired
  11. private LibraryCategoryService libraryCategoryService;
  12. @Autowired
  13. private CommentService commentService;
  14. @Autowired
  15. private TbOrderMapper orderMapper;
  16. @Autowired
  17. private TbRecordMapper recordMapper;
  18. @Value("${LOGIN_USER}")
  19. private String LOGIN_USER; // 当前登录用户的 session 存储 属性名
  20. @RequestMapping("/user_bookList")
  21. public String toLibraryListByCid(TbLibraryQuery libraryQuery, PageCount pageCount, Model model, HttpSession session) {
  22. if (libraryQuery == null || libraryQuery.getCateId() == null) {
  23. libraryQuery = new TbLibraryQuery();
  24. libraryQuery.setCateId((Integer) session.getAttribute("currentCategory"));
  25. }
  26. // 根据 类目 id
  27. // 若 当前 类目 为 父类目 则获取 其 下面 的 所有子类目
  28. // 若 当前 类目 为 子类目 则获取 其 同级 类目
  29. List<TbCategory> categoryList = libraryCategoryService.getCategoryByCid(libraryQuery.getCateId());
  30. // 获取当前类目信息
  31. TbCategory currentCategory = libraryCategoryService.getCategoryById(libraryQuery.getCateId());
  32. // 按照条件进行查询
  33. PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(libraryQuery, pageCount);
  34. // model 将数据设置到域中
  35. model.addAttribute("subCategoryList", categoryList);
  36. model.addAttribute("libraryPageCount", libraryPageCount);
  37. // 默认
  38. if (currentCategory == null) {
  39. currentCategory = new TbCategory();
  40. currentCategory.setId(0);
  41. }
  42. session.setAttribute("currentCategory", currentCategory.getId());
  43. return "/user/user_bookList";
  44. }
  45. /**
  46. * 通过 图书 id 查询 图书详细信息
  47. *
  48. * @param id
  49. * @return
  50. */
  51. @RequestMapping("/bookId")
  52. public String toBookInfo(int id, Model model) {
  53. BookExt bookInfo = libraryService.getBookInfoById(id);
  54. // 将 时间戳 进行转换
  55. Long dateSS = bookInfo.getLibrary().getCreatedate();
  56. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  57. String formatDate = simpleDateFormat.format(new Date(dateSS * 1000));
  58. bookInfo.setFormatDate(formatDate);
  59. // 通过 图书id 获取 回复信息
  60. List<CommentExt> commentExts = commentService.findCommentByBookId(id);
  61. // 将 查询的 图书信息 设置到 域 中
  62. model.addAttribute("bookInfo", bookInfo);
  63. // 将 回复信息 设置到 域 汇总
  64. model.addAttribute("commentExts", commentExts);
  65. return "/user/bookDetail";
  66. }
  67. /**
  68. * 用于 借阅 图书 操作
  69. *
  70. * @param session 用于 取 用户信息
  71. * @param order 用户借阅关联信息
  72. * @return
  73. */
  74. @RequestMapping("/jieyue_book")
  75. public String jieyueBook(HttpSession session, Model model, String oid, String kkid, TbOrder order) {
  76. if (null != kkid) {
  77. TbRecord tbRecord = recordMapper.selectByPrimaryKey(Integer.valueOf(kkid));
  78. tbRecord.setReturnbook(2); //2代表挂失
  79. recordMapper.updateByPrimaryKey(tbRecord);
  80. model.addAttribute("successMsg", "图书挂失成功");
  81. return "errorMsg";
  82. }
  83. if (null != oid) {
  84. TbRecord tbOrder = recordMapper.selectByPrimaryKey(Integer.valueOf(oid));
  85. // 插入数据
  86. tbOrder.setBackdate(tbOrder.getBackdate() + 3 * 30 * 24 * 60 * 60);
  87. recordMapper.updateByPrimaryKey(tbOrder);
  88. model.addAttribute("successMsg", "续借三个月成功");
  89. return "errorMsg";
  90. }
  91. // 获取 session 中的用户信息
  92. ActiveUser activeUser = (ActiveUser) session.getAttribute("activeUser");
  93. TbUser tbUser = new TbUser();
  94. tbUser.setId(activeUser.getUserid());
  95. order.setUserId(tbUser.getId());
  96. // 插入数据
  97. libraryService.jieyueBookById(order);
  98. return "redirect:/user/ch/bookId.action?id=" + order.getBookId();
  99. }
  100. @RequestMapping("/commitInfo")
  101. @ResponseBody
  102. public String commitComment(HttpSession session, TbComment comment) {
  103. // 获取 session 中的用户信息
  104. ActiveUser activeUser = (ActiveUser) session.getAttribute("activeUser");
  105. TbUser tbUser = new TbUser();
  106. tbUser.setId(activeUser.getUserid());
  107. comment.setUserId(tbUser.getId());
  108. libraryService.addCommentInfo(comment);
  109. return "ok";
  110. }
  111. }

源码获取:博客首页 "资源" 里下载! 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/58215
推荐阅读
相关标签
  

闽ICP备14008679号