In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how Java implements the online library management system. I hope you will get something after reading this article. Let's discuss it together.
I. brief introduction of the project
Functions: divided into administrator users and ordinary users, ordinary users: user login, personal information modification, book query, user borrowing, user return, administrator users: library, return management, borrowing information query, book maintenance, classification management, reader management and other functions.
II. Project operation
Environment configuration: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (both supported by IntelliJ IDEA,Eclispe,MyEclispe,Sts)
Project technology: JSP + Servlert + html+ css + JavaScript + JQuery + Ajax and so on.
User login module code: user login module: @ Controllerpublic 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" } / / responsible for handling loginCheck.html requests / / request parameters are automatically bound to @ 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") according to the default contract of the parameter name Boolean isReader = loginService.hasMatchReader (id, passwd); boolean isAdmin = loginService.hasMatchAdmin (id, passwd); HashMap 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", "administrator login succeeded!") ;} else if (isReader) {ReaderCard readerCard = loginService.findReaderCardByReaderId (id); request.getSession (). SetAttribute ("readercard", readerCard); res.put ("stateCode", "2"); res.put ("msg", "Reader login successful!") ;} else {res.put ("stateCode", "0"); res.put ("msg", "wrong account or password!") ;} 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", "password modified!") ; return "redirect:/admin_repasswd.html";} else {redirectAttributes.addFlashAttribute ("error", "password modification failed!") ; return "redirect:/admin_repasswd.html";}} else {redirectAttributes.addFlashAttribute ("error", "old password 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", "password modified!") ; return "redirect:/reader_repasswd.html";} else {redirectAttributes.addFlashAttribute ("error", "password modification failed!") ; return "redirect:/reader_repasswd.html";}} else {redirectAttributes.addFlashAttribute ("error", "old password error!") ; return "redirect:/reader_repasswd.html";}} / configure 404 page @ RequestMapping ("*") public String notFind () {return "404" }} static resource and interceptor configuration code: static resource and interceptor configuration: @ 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/") }} after reading this article, I believe you have a certain understanding of "how to implement the online library management system in Java". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.