Java实战项目之校园跑腿管理系统的实现
程序员文章站
2022-06-05 14:26:54
前端使用的是vue+elementui,这款系统只适合学习巩固springboot+vue,后面还要在这上面加校园公告、校园零食等功能,后期代码我也会持续更新上去。系统分为管理员和学生、学生是管理员后...
前端使用的是vue+elementui,这款系统只适合学习巩固springboot+vue,后面还要在这上面加校园公告、校园零食等功能,后期代码我也会持续更新上去。系统分为管理员和学生、学生是管理员后台添加的两种角色。
运行环境:
后端 jdk1.8、maven3.5/3.6 mysql5.7 idea/eclipse
前端 idea vue-cli node.js 搭建vue环境 webpack3.6.0指定版本
管理员控制层:
@controller @requestmapping(value = "admin") public class admincontroller { private final userservice userservice; private final goodservice goodservice; private final typeservice typeservice; private final orderservice orderservice; @autowired public admincontroller(userservice userservice, goodservice goodservice, typeservice typeservice, orderservice orderservice) { this.userservice = userservice; this.goodservice = goodservice; this.typeservice = typeservice; this.orderservice = orderservice; } @requestmapping(value = "/adminlogin", method = requestmethod.get) public string getadminlogin(){ return "admin/adminlogin"; } @requestmapping(value = "/adminlogin", method = requestmethod.post) public string postadminlogin(modelmap model, @requestparam(value = "email", required = false) string email, @requestparam(value = "password", required = false) string password, httpsession session) { user admin = userservice.getuserbyemail(email); string message; if (admin != null){ string mdspass = digestutils.md5digestashex((password + admin.getcode()).getbytes()); // if (!mdspass .equals(admin.getpassword())){ // message = "用户密码错误!"; // } if (!password .equals(admin.getpassword())){ message = "用户密码错误!"; } else if (admin.getroleid() != 101){ message = "用户没有权限访问!"; } else { session.setattribute("admin",admin); return "redirect:/admin/adminpage"; } } else { message = "用户不存在!"; } model.addattribute("message", message); return "admin/adminlogin"; } @requestmapping(value = "/adminlogout", method = requestmethod.get) public string adminlogout(@requestparam(required = false, defaultvalue = "false" )string adminlogout, httpsession session){ if (adminlogout.equals("true")){ session.removeattribute("admin"); } // adminlogout = "false"; return "redirect:/"; } @requestmapping(value = "/adminpage", method = requestmethod.get) public string getadminpage(modelmap model, httpsession session){ user admin = (user) session.getattribute("admin"); if (admin == null){ return "redirect:/admin/adminlogin"; } list<good> goodlist = goodservice.getallgoodlist(); for (good good : goodlist) { good.setgooduser(userservice.getuserbyid(good.getuserid())); good.setgoodsecondtype(typeservice.getsecondtypebyid(good.getsecondtypeid())); } list<user> userlist = userservice.getalluser(); list<firsttype> firsttypelist = typeservice.getallfirsttype(); list<order> orderlist = orderservice.getorderlist(); model.addattribute("goodlist", goodlist); model.addattribute("userlist", userlist); model.addattribute("firsttypelist", firsttypelist); model.addattribute("orderlist", orderlist); return "admin/adminpage"; } @requestmapping(value = "/user/update/status/{statusid}&{userid}", method = requestmethod.get) public responseentity updateuserstatus(@pathvariable integer statusid, @pathvariable integer userid){ boolean success = userservice.updateuserstatus(statusid, userid); if (success){ list<user> userlist = userservice.getalluser(); return responseentity.ok(userlist); } return responseentity.ok(success); } @requestmapping(value = "/user/delete/{userid}", method = requestmethod.get) public responseentity deleteuser(@pathvariable integer userid){ boolean success = userservice.deleteuser(userid); if (success){ list<user> userlist = userservice.getalluser(); return responseentity.ok(userlist); } return responseentity.ok(success); } }
用户控制层:
@controller @requestmapping(value = "user") public class usercontroller { private final goodservice goodservice; private final orderservice orderservice; private final reviewservice reviewservice; private final userservice userservice; private final collectservice collectservice; @autowired public usercontroller(goodservice goodservice, orderservice orderservice, reviewservice reviewservice, userservice userservice, collectservice collectservice) { this.goodservice = goodservice; this.orderservice = orderservice; this.reviewservice = reviewservice; this.userservice = userservice; this.collectservice = collectservice; } @requestmapping(value = "userprofile", method = requestmethod.get) public string getmyprofile(modelmap model, httpsession session) { user user = (user) session.getattribute("user"); if (user == null) { return "redirect:/"; } list<collect> collects = collectservice .getcollectbyuserid(user.getid()); for (collect collect : collects) { collect.setgood(goodservice.getgoodbyid(collect.getgoodid())); } list<good> goods = goodservice.getgoodbyuserid(user.getid()); list<order> orders = orderservice.getorderbycustomerid(user.getid()); list<review> reviews = reviewservice.gerreviewbytouserid(user.getid()); list<reply> replies = reviewservice.gerreplybytouserid(user.getid()); list<order> sellgoods = orderservice.getorderbysellerid(user.getid()); model.addattribute("collects", collects); model.addattribute("goods", goods); model.addattribute("orders", orders); model.addattribute("reviews", reviews); model.addattribute("replies", replies); model.addattribute("sellgoods", sellgoods); return "user/userprofile"; } @requestmapping(value = "/review", method = requestmethod.get) public string getreviewinfo(@requestparam(required = false) integer goodid, @requestparam(required = false) integer reviewid) { system.out.println("reviewid" + reviewid); if (reviewid != null) { system.out.println("reviewid" + reviewid); if (reviewservice.updatereviewstatus(1, reviewid) == 1) { return "redirect:/goods/goodinfo?goodid=" + goodid; } } return "redirect:/user/userprofile"; } @requestmapping(value = "/reply", method = requestmethod.get) public string getreplyinfo( @requestparam(required = false) integer reviewid, @requestparam(required = false) integer replyid) { if (replyid != null) { if (reviewservice.updatereplystatus(1, replyid) == 1) { integer goodid = reviewservice.getgoodidbyreviewid(reviewid); return "redirect:/goods/goodinfo?goodid=" + goodid; } } return "redirect:/user/userprofile"; } @requestmapping(value = "/useredit", method = requestmethod.get) public string getuseredit(modelmap model, @requestparam(value = "userid", required = false) integer userid, httpsession session) { user sessionuser = (user) session.getattribute("user"); if (sessionuser == null) { return "redirect:/"; } user user = userservice.getuserbyid(userid); list<order> sellgoods = orderservice.getorderbysellerid(user.getid()); list<review> reviews = reviewservice.gerreviewbytouserid(user.getid()); list<reply> replies = reviewservice.gerreplybytouserid(user.getid()); model.addattribute("user", user); model.addattribute("sellgoods", sellgoods); model.addattribute("reviews", reviews); model.addattribute("replies", replies); return "user/useredit"; } @requestmapping(value = "/useredit", method = requestmethod.post) public string postuseredit(modelmap model, @valid user user, httpsession session, @requestparam(value = "photo", required = false) multipartfile photo) throws ioexception { string status; boolean insertsuccess; user sessionuser = (user) session.getattribute("user"); user.setid(sessionuser.getid()); infocheck infocheck = new infocheck(); if (!infocheck.ismobile(user.getmobile())) { status = "请输入正确的手机号!"; } else if (!infocheck.isemail(user.getemail())) { status = "请输入正确的邮箱!"; } else if (userservice.getuserbymobile(user.getmobile()).getid() != user .getid()) { system.out.println(userservice.getuserbymobile(user.getmobile()) .getid() + " " + user.getid()); status = "此手机号码已使用!"; } else if (userservice.getuserbyemail(user.getemail()).getid() != user .getid()) { status = "此邮箱已使用!"; } else { if (!photo.isempty()) { randomstring randomstring = new randomstring(); filecheck filecheck = new filecheck(); string filepath = "/statics/image/photos/" + user.getid(); string pathroot = filecheck.checkgoodfolderexist(filepath); string filename = user.getid() + randomstring.getrandomstring(10); string contenttype = photo.getcontenttype(); string imagename = contenttype.substring(contenttype .indexof("/") + 1); string name = filename + "." + imagename; photo.transferto(new file(pathroot + name)); string photourl = filepath + "/" + name; user.setphotourl(photourl); } else { string photourl = userservice.getuserbyid(user.getid()) .getphotourl(); user.setphotourl(photourl); } insertsuccess = userservice.updateuser(user); if (insertsuccess) { session.removeattribute("user"); session.setattribute("user", user); return "redirect:/user/userprofile"; } else { status = "修改失败!"; model.addattribute("user", user); model.addattribute("status", status); return "user/useredit"; } } system.out.println(user.getmobile()); system.out.println(status); model.addattribute("user", user); model.addattribute("status", status); return "user/useredit"; } @requestmapping(value = "/password/edit", method = requestmethod.post) public responseentity editpassword(@requestbody password password) { user user = userservice.getuserbyid(password.getuserid()); string oldpass = digestutils .md5digestashex((password.getoldpassword() + user.getcode()) .getbytes()); if (oldpass.equals(user.getpassword())) { randomstring randomstring = new randomstring(); string code = (randomstring.getrandomstring(5)); string md5pass = digestutils.md5digestashex((password .getnewpassword() + code).getbytes()); boolean success = userservice.updatepassword(md5pass, code, password.getuserid()); if (success) { return responseentity.ok(true); } else { return responseentity.ok("密码修改失败!"); } } else { return responseentity.ok("原密码输入不正确!"); } } }
类型控制层:
@controller @requestmapping("type") public class typecontroller { private final typeservice typeservice; private final goodservice goodservice; @autowired public typecontroller(typeservice typeservice, goodservice goodservice) { this.typeservice = typeservice; this.goodservice = goodservice; } @requestmapping(value = "/secondtype/{firsttypeid}", method = requestmethod.get) public responseentity getsecondtypeid(@pathvariable integer firsttypeid) { list<secondtype> secondtypes = typeservice .getsecondtypebyfirsttypeid(firsttypeid); if (secondtypes == null) { return responseentity.ok("isnull"); } return responseentity.ok(secondtypes); } @requestmapping(value = "/secondtype/delete/{secondtypeid}", method = requestmethod.get) public responseentity deletesecondtype(@pathvariable integer secondtypeid) { boolean success = goodservice.getgoodsadminbytype(secondtypeid) .isempty(); system.out.println(goodservice.getgoodsadminbytype(secondtypeid)); if (success) { integer thisfirsttypeid = typeservice.getsecondtypebyid( secondtypeid).getfirsttypeid(); success = typeservice.deletesecondtype(secondtypeid); if (success) { list<secondtype> secondtypelist = typeservice .getsecondtypebyfirsttypeid(thisfirsttypeid); if (secondtypelist == null) { return responseentity.ok("isnull"); } return responseentity.ok(secondtypelist); } } return responseentity.ok(success); } @requestmapping(value = "/firsttype/delete/{firsttypeid}", method = requestmethod.get) public responseentity deletefirsttype(@pathvariable integer firsttypeid) { boolean success = typeservice.getsecondtypebyfirsttypeid(firsttypeid) .isempty(); if (success) { success = typeservice.deletefirsttype(firsttypeid); if (success) { list<firsttype> firsttypelist = typeservice.getallfirsttype(); if (firsttypelist == null) { return responseentity.ok("isnull"); } return responseentity.ok(firsttypelist); } } return responseentity.ok(success); } @requestmapping(value = "/secondtype/create", method = requestmethod.post) public responseentity createsecondtype(@requestbody secondtype secondtype) { integer thisfirsttypeid = secondtype.getfirsttypeid(); boolean success = typeservice.createsecondtype(secondtype); if (success) { list<secondtype> secondtypelist = typeservice .getsecondtypebyfirsttypeid(thisfirsttypeid); return responseentity.ok(secondtypelist); } return responseentity.ok(success); } @requestmapping(value = "/firsttype/create", method = requestmethod.post) public responseentity createsecondtype(@requestbody firsttype firsttype) { boolean success = typeservice.createfirsttype(firsttype); if (success) { list<firsttype> firsttypelist = typeservice.getallfirsttype(); return responseentity.ok(firsttypelist); } return responseentity.ok(success); } }
到此这篇关于java实战项目之校园跑腿管理系统的实现的文章就介绍到这了,更多相关java 校园跑腿管理系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: python奇偶行分开实现方法
下一篇: day 8 - 1 文件操作