Java 实战项目锤炼之网上图书馆管理系统的实现流程
程序员文章站
2024-01-05 09:58:52
一、项目简述功能: 区分为管理员用户和普通用户,普通用户:用户登录,个 人信息修改,图书查询,用户借阅,用户归还,管理员用 户:图书馆里,归还管理,借阅信息查询,图书维护,分 类管理,读者管理等等功能...
一、项目简述
功能: 区分为管理员用户和普通用户,普通用户:用户登录,个 人信息修改,图书查询,用户借阅,用户归还,管理员用 户:图书馆里,归还管理,借阅信息查询,图书维护,分 类管理,读者管理等等功能。
二、项目运行
环境配置: jdk1.8 + tomcat8.5 + mysql + eclispe (intellij idea,eclispe,myeclispe,sts 都支持)
项目技术: 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"; } //负责处理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"; } }
静态资源和拦截器配置代码:
静态资源和拦截器配置: @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 实战项目锤炼之网上图书馆管理系统的实现流程的详细内容,更多关于java 图书馆管理系统的资料请关注其它相关文章!