您好,登錄后才能下訂單哦!
小編給大家分享一下Java如何實現(xiàn)網(wǎng)上圖書館管理系統(tǒng),希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
功能: 區(qū)分為管理員用戶和普通用戶,普通用戶:用戶登錄,個 人信息修改,圖書查詢,用戶借閱,用戶歸還,管理員用 戶:圖書館里,歸還管理,借閱信息查詢,圖書維護(hù),分 類管理,讀者管理等等功能。
環(huán)境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
項目技術(shù): JSP + Servlert + html+ css + JavaScript + JQuery + Ajax等等。
用戶登陸模塊: @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"; } //負(fù)責(zé)處理loginCheck.html請求 //請求參數(shù)會根據(jù)參數(shù)名稱默認(rèn)契約自動綁定到相應(yīng)方法的入?yún)⒅? @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"; } }
靜態(tài)資源和攔截器配置: @Configuration @EnableWebMvc @ComponentScan("com.library.controller") public class WebConfig extends WebMvcConfigurerAdapter { @Bean public ViewResolver viewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setSuffix(".jsp"); return resolver; } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/img/**") .addResourceLocations("/static/img/"); registry.addResourceHandler("/js/**").addResourceLocations("/static/js/"); registry.addResourceHandler("/css/**").addResourceLocations("/static/css/"); } }
看完了這篇文章,相信你對“Java如何實現(xiàn)網(wǎng)上圖書館管理系統(tǒng)”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。