<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
環境設定:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支援)
專案技術:
HTML +Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等。
@Controller public class LoginController { private LoginService loginService; @Autowired public void setLoginService(LoginService loginService) { this.loginService = loginService; } @RequestMapping(value = {"/", "/login.html"}) public String toLogin(HttpServletRequest request) { request.getSession().invalidate(); return "index"; } @RequestMapping("/logout.html") public String logout(HttpServletRequest request) { request.getSession().invalidate(); return "redirect:/login.html"; } //負責處理loginCheck.html請求 //請求引數會根據引數名稱預設契約自動繫結到相應方法的入參中 @RequestMapping(value = "/api/loginCheck", method = RequestMethod.POST) public @ResponseBody Object loginCheck(HttpServletRequest request) { long id = Long.parseLong(request.getParameter("id")); String passwd = request.getParameter("passwd"); boolean isReader = loginService.hasMatchReader(id, passwd); boolean isAdmin = loginService.hasMatchAdmin(id, passwd); HashMap<String, String> res = new HashMap<>(); if (isAdmin) { Admin admin = new Admin(); admin.setAdminId(id); admin.setPassword(passwd); String username = loginService.getAdminUsername(id); admin.setUsername(username); request.getSession().setAttribute("admin", admin); res.put("stateCode", "1"); res.put("msg", "管理員登陸成功!"); } else if (isReader) { ReaderCard readerCard = loginService.findReaderCardByReaderId(id); request.getSession().setAttribute("readercard", readerCard); res.put("stateCode", "2"); res.put("msg", "讀者登陸成功!"); } else { res.put("stateCode", "0"); res.put("msg", "賬號或密碼錯誤!"); } return res; } @RequestMapping("/admin_main.html") public ModelAndView toAdminMain(HttpServletResponse response) { return new ModelAndView("admin_main"); } @RequestMapping("/reader_main.html") public ModelAndView toReaderMain(HttpServletResponse response) { return new ModelAndView("reader_main"); } @RequestMapping("/admin_repasswd.html") public ModelAndView reAdminPasswd() { return new ModelAndView("admin_repasswd"); } @RequestMapping("/admin_repasswd_do") public String reAdminPasswdDo(HttpServletRequest request, String oldPasswd, String newPasswd, String reNewPasswd, RedirectAttributes redirectAttributes) { Admin admin = (Admin) request.getSession().getAttribute("admin"); long id = admin.getAdminId(); String password = loginService.getAdminPassword(id); if (password.equals(oldPasswd)) { if (loginService.adminRePassword(id, newPasswd)) { redirectAttributes.addFlashAttribute("succ", "密碼修改成功!"); return "redirect:/admin_repasswd.html"; } else { redirectAttributes.addFlashAttribute("error", "密碼修改失敗!"); return "redirect:/admin_repasswd.html"; } } else { redirectAttributes.addFlashAttribute("error", "舊密碼錯誤!"); return "redirect:/admin_repasswd.html"; } } @RequestMapping("/reader_repasswd.html") public ModelAndView reReaderPasswd() { return new ModelAndView("reader_repasswd"); } @RequestMapping("/reader_repasswd_do") public String reReaderPasswdDo(HttpServletRequest request, String oldPasswd, String newPasswd, String reNewPasswd, RedirectAttributes redirectAttributes) { ReaderCard reader = (ReaderCard) request.getSession().getAttribute("readercard"); long id = reader.getReaderId(); String password = loginService.getReaderPassword(id); if (password.equals(oldPasswd)) { if (loginService.readerRePassword(id, newPasswd)) { redirectAttributes.addFlashAttribute("succ", "密碼修改成功!"); return "redirect:/reader_repasswd.html"; } else { redirectAttributes.addFlashAttribute("error", "密碼修改失敗!"); return "redirect:/reader_repasswd.html"; } } else { redirectAttributes.addFlashAttribute("error", "舊密碼錯誤!"); return "redirect:/reader_repasswd.html"; } } //設定404頁面 @RequestMapping("*") public String notFind() { return "404"; } }
@Controller public class BookController { @Autowired private BookService bookService; @Autowired private LendService lendService; private Date getDate(String pubstr) { try { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); return df.parse(pubstr); } catch (ParseException e) { e.printStackTrace(); return new Date(); } } @RequestMapping("/queryBook.html") public ModelAndView queryBookDo(String searchWord) { if (bookService.matchBook(searchWord)) { ArrayList<Book> books = bookService.queryBook(searchWord); ModelAndView modelAndView = new ModelAndView("admin_books"); modelAndView.addObject("books", books); return modelAndView; } else { return new ModelAndView("admin_books", "error", "沒有匹配的圖書"); } } @RequestMapping("/reader_querybook_do.html") public ModelAndView readerQueryBookDo(String searchWord) { if (bookService.matchBook(searchWord)) { ArrayList<Book> books = bookService.queryBook(searchWord); ModelAndView modelAndView = new ModelAndView("reader_books"); modelAndView.addObject("books", books); return modelAndView; } else { return new ModelAndView("reader_books", "error", "沒有匹配的圖書"); } } @RequestMapping("/admin_books.html") public ModelAndView adminBooks() { ArrayList<Book> books = bookService.getAllBooks(); ModelAndView modelAndView = new ModelAndView("admin_books"); modelAndView.addObject("books", books); return modelAndView; } @RequestMapping("/book_add.html") public ModelAndView addBook() { return new ModelAndView("admin_book_add"); } @RequestMapping("/book_add_do.html") public String addBookDo(@RequestParam(value = "pubstr") String pubstr, Book book, RedirectAttributes redirectAttributes) { book.setPubdate(getDate(pubstr)); if (bookService.addBook(book)) { redirectAttributes.addFlashAttribute("succ", "圖書新增成功!"); } else { redirectAttributes.addFlashAttribute("succ", "圖書新增失敗!"); } return "redirect:/admin_books.html"; } @RequestMapping("/updatebook.html") public ModelAndView bookEdit(HttpServletRequest request) { long bookId = Long.parseLong(request.getParameter("bookId")); Book book = bookService.getBook(bookId); ModelAndView modelAndView = new ModelAndView("admin_book_edit"); modelAndView.addObject("detail", book); return modelAndView; } @RequestMapping("/book_edit_do.html") public String bookEditDo(@RequestParam(value = "pubstr") String pubstr, Book book, RedirectAttributes redirectAttributes) { book.setPubdate(getDate(pubstr)); if (bookService.editBook(book)) { redirectAttributes.addFlashAttribute("succ", "圖書修改成功!"); } else { redirectAttributes.addFlashAttribute("error", "圖書修改失敗!"); } return "redirect:/admin_books.html"; } @RequestMapping("/admin_book_detail.html") public ModelAndView adminBookDetail(HttpServletRequest request) { long bookId = Long.parseLong(request.getParameter("bookId")); Book book = bookService.getBook(bookId); ModelAndView modelAndView = new ModelAndView("admin_book_detail"); modelAndView.addObject("detail", book); return modelAndView; } @RequestMapping("/reader_book_detail.html") public ModelAndView readerBookDetail(HttpServletRequest request) { long bookId = Long.parseLong(request.getParameter("bookId")); Book book = bookService.getBook(bookId); ModelAndView modelAndView = new ModelAndView("reader_book_detail"); modelAndView.addObject("detail", book); return modelAndView; } @RequestMapping("/admin_header.html") public ModelAndView admin_header() { return new ModelAndView("admin_header"); } @RequestMapping("/reader_header.html") public ModelAndView reader_header() { return new ModelAndView("reader_header"); } @RequestMapping("/reader_books.html") public ModelAndView readerBooks(HttpServletRequest request) { ArrayList<Book> books = bookService.getAllBooks(); ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard"); ArrayList<Lend> myAllLendList = lendService.myLendList(readerCard.getReaderId()); ArrayList<Long> myLendList = new ArrayList<>(); for (Lend lend : myAllLendList) { // 是否已歸還 if (lend.getBackDate() == null) { myLendList.add(lend.getBookId()); } } ModelAndView modelAndView = new ModelAndView("reader_books"); modelAndView.addObject("books", books); modelAndView.addObject("myLendList", myLendList); return modelAndView; } }
@Controller public class ReaderController { @Autowired private ReaderInfoService readerInfoService; @Autowired private LoginService loginService; @Autowired private ReaderCardService readerCardService; private ReaderInfo getReaderInfo(long readerId, String name, String sex, String birth, String address, String phone) { ReaderInfo readerInfo = new ReaderInfo(); Date date = new Date(); try { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); date = df.parse(birth); } catch (ParseException e) { e.printStackTrace(); } readerInfo.setAddress(address); readerInfo.setName(name); readerInfo.setReaderId(readerId); readerInfo.setPhone(phone); readerInfo.setSex(sex); readerInfo.setBirth(date); return readerInfo; } @RequestMapping("allreaders.html") public ModelAndView allBooks() { ArrayList<ReaderInfo> readers = readerInfoService.readerInfos(); ModelAndView modelAndView = new ModelAndView("admin_readers"); modelAndView.addObject("readers", readers); return modelAndView; } @RequestMapping("reader_delete.html") public String readerDelete(HttpServletRequest request, RedirectAttributes redirectAttributes) { long readerId = Long.parseLong(request.getParameter("readerId")); if (readerInfoService.deleteReaderInfo(readerId) && readerCardService.deleteReaderCard(readerId)) { redirectAttributes.addFlashAttribute("succ", "刪除成功!"); } else { redirectAttributes.addFlashAttribute("error", "刪除失敗!"); } return "redirect:/allreaders.html"; } @RequestMapping("/reader_info.html") public ModelAndView toReaderInfo(HttpServletRequest request) { ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard"); ReaderInfo readerInfo = readerInfoService.getReaderInfo(readerCard.getReaderId()); ModelAndView modelAndView = new ModelAndView("reader_info"); modelAndView.addObject("readerinfo", readerInfo); return modelAndView; } @RequestMapping("reader_edit.html") public ModelAndView readerInfoEdit(HttpServletRequest request) { long readerId = Long.parseLong(request.getParameter("readerId")); ReaderInfo readerInfo = readerInfoService.getReaderInfo(readerId); ModelAndView modelAndView = new ModelAndView("admin_reader_edit"); modelAndView.addObject("readerInfo", readerInfo); return modelAndView; } @RequestMapping("reader_edit_do.html") public String readerInfoEditDo(HttpServletRequest request, String name, String sex, String birth, String address, String phone, RedirectAttributes redirectAttributes) { long readerId = Long.parseLong(request.getParameter("readerId")); ReaderInfo readerInfo = getReaderInfo(readerId, name, sex, birth, address, phone); if (readerInfoService.editReaderInfo(readerInfo) && readerInfoService.editReaderCard(readerInfo)) { redirectAttributes.addFlashAttribute("succ", "讀者資訊修改成功!"); } else { redirectAttributes.addFlashAttribute("error", "讀者資訊修改失敗!"); } return "redirect:/allreaders.html"; } @RequestMapping("reader_add.html") public ModelAndView readerInfoAdd() { return new ModelAndView("admin_reader_add"); } @RequestMapping("reader_add_do.html") public String readerInfoAddDo(String name, String sex, String birth, String address, String phone, String password, RedirectAttributes redirectAttributes) { ReaderInfo readerInfo = getReaderInfo(0, name, sex, birth, address, phone); long readerId = readerInfoService.addReaderInfo(readerInfo); readerInfo.setReaderId(readerId); if (readerId > 0 && readerCardService.addReaderCard(readerInfo, password)) { redirectAttributes.addFlashAttribute("succ", "新增讀者資訊成功!"); } else { redirectAttributes.addFlashAttribute("succ", "新增讀者資訊失敗!"); } return "redirect:/allreaders.html"; } @RequestMapping("reader_info_edit.html") public ModelAndView readerInfoEditReader(HttpServletRequest request) { ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard"); ReaderInfo readerInfo = readerInfoService.getReaderInfo(readerCard.getReaderId()); ModelAndView modelAndView = new ModelAndView("reader_info_edit"); modelAndView.addObject("readerinfo", readerInfo); return modelAndView; } @RequestMapping("reader_edit_do_r.html") public String readerInfoEditDoReader(HttpServletRequest request, String name, String sex, String birth, String address, String phone, RedirectAttributes redirectAttributes) { ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard"); ReaderInfo readerInfo = getReaderInfo(readerCard.getReaderId(), name, sex, birth, address, phone); if (readerInfoService.editReaderInfo(readerInfo) && readerInfoService.editReaderCard(readerInfo)) { ReaderCard readerCardNew = loginService.findReaderCardByReaderId(readerCard.getReaderId()); request.getSession().setAttribute("readercard", readerCardNew); redirectAttributes.addFlashAttribute("succ", "資訊修改成功!"); } else { redirectAttributes.addFlashAttribute("error", "資訊修改失敗!"); } return "redirect:/reader_info.html"; } }
到此這篇關於Java實戰之圖書管理系統的實現的文章就介紹到這了,更多相關Java圖書管理系統內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45