本系统主要实现的功能有:
网上商城系统,前台+后台管理,用户注册,登录,商品展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,用户管理,信息修改等等。
环境配置:
jdk1.8 + tomcat8.5 + mysql + eclispe(intellij idea,eclispe,myeclispe,sts都支持)
项目技术:
springboot+ springmvc + mybatis + jsp + html+ javascript + jquery + ajax + maven等等
后台管理代码:
@controllerpublic class indexcontroller { /** * 网站首页 * */ @getmapping("/") public string index(){ return "/index"; } /** * 联系我们 * */ @getmapping("/contacts") public string contacts(){ return "/common/contacts"; } /** * 关于我们 * */ @getmapping("/about") public string about(){ return "/common/about"; } /** * 后台管理首页 * */ @getmapping("/admin/index") public string adminindex(httpssion ssion, httprvletrequest request, httprvletrespon respon) throws ioexception { string admin = (string) ssion.getattribute("admin"); /**拦截器:如果不是管理员,则进行重定向*/ if (stringutils.impty(admin)){ respon.ndredirect(request.getcontextpath() + "/");//重定向 } return "/admin/index"; } /** * 用户登录注册 * */ @getmapping("/login") public string login(){ return "/ur/logreg"; } /** * 用户忘记密码 * */ @getmapping("/forget") public string forget(){ return "ur/forget"; } /** * 个人中心 * */ @getmapping("/ur/center") public string urcenter(httpssion ssion, httprvletrequest request, httprvletrespon respon) throws ioexception { string urid = (string) ssion.getattribute("urid"); /**拦截器:如果不是用户角色登录,则进行重定向*/ if (stringutils.impty(urid)){ respon.ndredirect(request.getcontextpath() + "/");//重定向 } return "/ur/ur-center"; } /** * 用户修改密码 * */ @requirespermissions("ur:urinfo") @getmapping("/ur/pass") public string urinfo(){ return "/ur/updatepass"; } /** * 用户更换手机号 * */ @requirespermissions("ur:urinfo") @getmapping("/ur/phone") public string urphone(){ return "/ur/updatephone"; } /** * 用户商品列表 * */ @getmapping("/ur/product") public string urproduct(){ return "/ur/product/productlist"; } /** * 通知消息 * */ @getmapping("/ur/message") public string commonmessage(){ return "/ur/message/message"; } /** * 弹出式通知消息 * */ @getmapping("/ur/alertmessage") public string alertmessage(){ return "/ur/message/alertmessage"; } /** * 跳转到产品清单界面 * */ @getmapping("/product-listing") public string toproductlisting() { return "/common/product-listing"; } /** * 跳转到产品清单搜索界面 * */ @getmapping("/product-arch") public string toproductarchs(string keys, modelmap modelmap) { if(keys==null){ return "/error/404"; } modelmap.put("keys",keys); return "/common/product-arch"; } /**用户个人中心默认展示图*/ @getmapping("/home/console") public string homeconsole(){ return "/admin/home/console"; } /** * 管理员首页默认展示图 * */ @getmapping("/echars/console") public string echars(){ return "/admin/echars/console"; } @getmapping("/app/message/index") public string appmessageindex(){ return "/admin/app/message/index"; } /** * 用户收藏列表 * */ @getmapping("/ur/collect") public string urcollect(){ return "/ur/collect/collectlist"; } /** * 用户售出记录 * */ @getmapping("/ur/sold") public string sold(){ return "/ur/sold/soldrecord"; } /** * 销量列表 * */ @getmapping("/admin/sold") public string adminsold(){ return "/admin/sold/soldrecord"; } /** * 首页公告清单 * */ @getmapping("/ur/newslist") public string urnews(){ return "/common/listnews"; } /** * 管理员公告列表 * */ @getmapping("/admin/newslist") public string adminnews(){ return "/admin/news/newslist"; }}
订单和商品服务类:
@webrvlet("/backstage_goodsrvlet")public class goodsrvlet extends httprvlet{goodsrvice rvice = new goodsrvice();@overrideprotected void rvice(httprvletrequest req, httprvletrespon resp) throws rvletexception, ioexception {string action = req.getparameter("action");switch(action) {ca "addgoods":addgoods(req,resp);break;ca "getgoodslist":getgoodslist(req,resp);break;ca "getgoodslistbyname":getgoodslistbyname(req,resp);break;ca "deletegoods":deletegoods(req,resp);break;ca "togoodsupdatepage":togoodsupdatepage(req,resp);break;ca "updategoods":updategoods(req,resp);break;ca "upgoodsimage":upgoodsimage(req,resp);break;ca "fastbuy":ndorder(req,resp);break;}}/*** 提交订单* @throws ioexception */public void ndorder(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");simpledateformat df = new simpledateformat("yyyy-mm-dd hh:mm:ss");//设置日期格式orders order = new orders();order.tnumber(order.getrandomstring(10));order.ttime(df.format(new date()));order.tname(req.getparameter("recipients"));order.taddress(req.getparameter("address"));order.tphone(req.getparameter("phone"));order.taddress_label(req.getparameter("addresslabel"));order.tx(req.getparameter("x"));order.tur("sjb");order.tgoods_id(99);order.tgoods_num(3);order.tgoods_status(1);int d = rvice.addorder(order);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult error = jsonresult.errormsg("订单提交失败!");resp.getwriter().println(jsonutil.javaobjecttojson(error));}} catch (exception e) {e.printstacktrace();}}/*** 保存商品* @throws ioexception */public void addgoods(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");fileuploadutil upfile = new fileuploadutil();rvletcontext rvletcontext = req.getssion().getrvletcontext();list<fileitem> items= upfile.getrequtfileitems(req,rvletcontext);//保存所有用户提交的 表单数据 的mapmap<string, string> formdata = new hashmap<>();string savepath = new file(getrvletcontext().getrealpath("/")).getparentfile().getparentfile().getpath()+"/imgs";try {//遍历for (fileitem file : items) {if(!file.isformfield()) {string filesuffix = fileuploadutil.getfilesuffix(file).toupperca();//必须是jpg或png 图片文件才能进行上传操作if("jpg".equals(filesuffix) || "png".equals(filesuffix)) {//生成新图片名string imgname = fileuploadutil.getimgnewname(filesuffix);fileuploadutil.savefile(file, savepath, imgname);formdata.put("imgurl",imgname);}}el {//非文件数据存入formdata.put(file.getfieldname(), file.getstring("utf-8"));}}} catch (unsupportedencodingexception e) {e.printstacktrace();}goods goods = new goods();goods.tname(formdata.get("goodsname"));goods.tnum(integer.parint(formdata.get("num")));goods.tprice(double.pardouble(formdata.get("price")));goods.timgurl(formdata.get("imgurl"));goods.ttype(formdata.get("type"));goods.tdescription(formdata.get("description"));goods.tcolor(formdata.get("color"));goods.tmemory(formdata.get("memory"));goods.tcreatedate(new simpledateformat("yyyy四大名著及作者-mm-dd").format(new date()));int d = rvice.addgoods(goods);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.java二十英语objecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("添加失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 向前端页面返回商品数据列表*/public void getgoodslist(httprvletrequest req,httprvletrespon resp) {list<goods> allgoods = rvice.getallgoods();req.tattribute("goodslist", allgoods);try {req.getrequestdispatcher("/backstage/tgls/goodsmanage/goods_list.jsp").forward(req, resp);} catch (rvletexception e) {e.printstacktrace();} catch (ioexception e) {e.printstacktrace();}}/*** @throws ioexception * 根据商品名查询商品* @param req* @param resp* @throws */public void getgoodslistbyname(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");string name = req.getparameter("goodsname");string type = req.getparameter("type");map<string,string> parmas = new hashmap<>();parmas.put("name", name);parmas.put("type", type);list<goods> list = rvice.getgoodsbyname(parmas);try {if(list != null) {jsonresult ok = jsonresult.ok(list);resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("未获取到任何数据,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 修改商品时,获取此商品的全部数据,并返回至修改页面*/public void togoodsupdatepage(httprvletrequest req,httprvletrespon resp) {int id = integer.parint(req.getparameter("id"));goods goods = rvice.getgoodsinfobyid(id);req.tattribute("goods", goods);try {req.getrequestdispatcher("/backstage/tgls/goodsmanage/goods_update.jsp").forward(req, resp);} catch (rvletexception e) {e.printstacktrace我国直辖市有几个();} catch (ioexception e) {e.printstacktrace();}}/***修改商品信息时,如果有修改图片,先将图片进行修改* @throws ioexception */public void upgoodsimage(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");fileuploadutil upfile = new fileuploadutil();rvletcontext rvletcontext = req.getssion().getrvletcontext();list<fileitem> items= upfile.getrequtfileitems(req,rvletcontext);string savepath = new file(getrvletcontext().getrealpath("/")).getparentfile().getparentfile().getpath()+"/imgs";string imgname = null;try {//遍历for (fileitem file : items) {if(!file.isformfield()) {string filesuffix = fileuploadutil.getfilesuffix(file);//必须是jpg或png 图片文件才能进行上传操作if("jpg".equals(filesuffix) || "png".equals(filesuffix)) {//生成新图片名imgname = fileuploadutil.getimgnewname(filesuffix);fileuploadutil.savefile(file, savepath, imgname);}}}int d = rvice.updategoodsimgbyid(imgname, integer.parint(req.getparameter("id")));if(d>0) {jsonresult ok = jsonresult.ok(imgname);resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("修改失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 修改商品* @throws ioexception */public void updategoods(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");goods goods = new goods();goods.tid(integer.parint(req.getparameter("id")));goods.tname(req.getparameter("goodsname"));goods.tnum(integer.parint(req.getparameter("num")));goods.tprice(double.pardouble(req.getparameter("price")));goods.ttype(req.getparameter("type"));goods.tcolor(req.getparameter("color"));goods.tmemory(req.getparameter("memory"));goods.tdescription(req.getparameter("description"));int d = rvice.updategoodsbyid(goods);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("修改失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 删除商品* @throws ioexception */public void deletegoods(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");int id = integer.parint(req.getparameter("id"));int d = rvice.deletegoodsbyid(id);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("删除失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}}
订单服务类:
@webrvlet("/backstage_ordersrvlet")public class ordersrvlet extends httprvlet{ordersrvice rvice = new ordersrvice();@overrideprotected void rvice(httprvletrequest req, httprvletrespon resp) throws rvletexception, ioexception {string action = req.getparameter("action");system.out.println(action);switch(action) {ca "getorderslist":getorderslist(req,resp);break;ca "getorderslistbyname":getorderslistbyname(req,resp);break;ca "deleteorders":deleteorders(req,resp);break;ca "deleteallorders":deleteallorders(req,resp);break;ca "toordersupdatepage":toordersupdatepage(req,resp);break;ca "updateorders":updateorders(req,resp);break;ca "fastbuy":ndorder(req,resp);break;}}/* * 删除全部订单 */private void deleteallorders(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");// todo 自动生成的方法存化妆需要什么根int d = rvice.deleteallorders();try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("删除失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 提交订单* @throws ioexception */public void ndorder(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");simpledateformat df = new simpledateformat("yyyy-mm-dd hh:mm:ss");//设置日期格式ur ur =(ur) req.getssion().getattribute("ur");orders order = new orders();order.tnumber(order.getrandomstring(10));order.ttime(df.format(new date()));order.tname(req.getparameter("recipients"));order.taddress(req.getparameter("address"));order.tphone(req.getparameter("phone"));order.taddress_label(req.getparameter("addresslabel"));order.tx(req.getparameter("x"));order.tur(ur.geturname());order.tgoods_id(integer.parint(req.getpara分数的再认识meter("id")));order.tgoods_num(integer.parint(req.getparameter("num")));order.tgoods_status(1);int d = rvice.addorder(order);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult error = jsonresult.errormsg("订单提交失败!");resp.getwriter().println(jsonutil.javaobjecttojson(error));}} catch (exception e) {e.printstacktrace();}}/*** 向前端页面返回订单数据列表*/public void getorderslist(httprvletrequest req,httprvletrespon resp) {list<orders> allorders = rvice.getallorders();req.tattribute("orderslist",allorders);try {req.getrequestdispatcher("/backstage/tgls/ordersmanage/orders_list.jsp").forward(req, resp);} catch (rvletexception e) {e.printstacktrace();} catch (ioexception e) {e.printstacktrace();}}/*** 根据订单名查询商品(注意!类别没改)* @param req* @param resp* @throws ioexception */public void getorderslistbyname(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");string name = req.getparameter("ordersur");//string type = req.getparameter("type");map<string,string> parmas = new hashmap<>();parmas.put("name", name);//parmas.put("type", type);list<orders> list = rvice.getordersbyname(parmas);try {if(list != null) {jsonresult ok = jsonresult.ok(list);resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("未获取到任何数据,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 修改订单时,获取此订单的全部数据,并返回至修改页面*/public void toordersupdatepage(httprvletrequest req,httprvletrespon resp) {int id = integer.parint(req.getparameter("id"));orders orders = rvice.getordersinfobyid(id);req.tattribute("orders", orders);try {req.getrequestdispatcher("/backstage/tgls/ordersmanage/orders_update.jsp").forward(req, resp);} catch (rvletexception e) {e.printstacktrace();} catch (ioexception e) {e.printstacktrace();}}/*** 修改订单* @throws ioexception */public void updateorders(httprvletrequest req,httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");orders orders = new orders();orders.tid(integer.parint(req.getparameter("id")));orders.tnumber(req.getparameter("number"));orders.tur(req.getparameter("ur"));orders.ttime(req.getparameter("time"));orders.tname(req.getparameter("name"));orders.tx(req.getparameter("x"));orders.taddress(req.getparameter("address"));orders.tphone(req.getparameter("phone"));orders.taddress_label(req.getparameter("address_label"));orders.tgoods_id(integer.parint(req.getparameter("goods_id")));orders.tgoods_num(integer.parint(req.getparameter("goods_num")));orders.tgoods_status(integer.parint(req.getparameter("goods_status")));system.out.println(orders);int d = rvice.updateordersbyid(orders);system.out.println(d);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("修改失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 删除订单* @throws unsupportedencodingexception */public void deleteorders(httprvletrequest req,httprvletrespon resp) throws unsupportedencodingexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");int id = integer.parint(req.getparameter("id"));int d = rvice.deleteordersbyid(id);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("删除失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}}
用户服务类:
@webrvlet("/backstage_urrvlet")public class urrvlet extends httprvlet{urrvice rvice = new urrvice();@overrideprotected void rvice(httprvletrequest req, httprvletrespon resp) throws rvletexception, ioexception {string action = req.getparameter("action");switch(action) {ca "login":login(req, resp);break;ca "modifypassword":modifypassword(req, resp);break;ca "checkoldpassword":checkoldpassword(req, resp);break;ca "aftermodifypassword":aftermodifypassword(req, resp);break;ca "logout":logout(req, resp);break;}}/*** 用户登录* @throws ioexception */public void login(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");//获取前端页面传来的用户名string urname = req.getparameter("urname");//获取前端页面传来的密码string password = req.getparameter("password");// 1、先验证该用户的角色是否为管理员string urrole = rvice.geturrolebyname(urname);try {if(!"admin".equals(urrole)) {jsonresult errormsg = jsonresult.errormsg("暂无登录权限");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}el {//2、获取用户数据 进行用户名和密码验证ur ur = rvice.geturbynameandpassword(urname, password);if(ur!=null) {//将用户数据保存到ssion 作用域中,方便在后续的操作中使用用户数据req.getssion().tattribute("ur", ur);jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {// 将错误信息封装在结果集中jsonresult result = jsonresult.errormsg("用户名或密码错误,请重试");//以json的形式返回给前端resp.getwriter().println(jsonutil.javaobjecttojson(result));}}} catch (exception e) {e.printstacktrace();}}/*** 检查旧密码是否正确 ,在修改密码操作时使用* @throws ioexception */public void checkoldpassword(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");ur ur =(ur) req.getssion().getattribute("ur");string oldpassword = rvice.getpasswordbyid(ur.getid()); string password = req.getparameter("password");try {if(!oldpassword.equals(password)) {jsonresult errormsg = jsonresult.errormsg("原始密码错误,请重新输入");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}el {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}} catch (ioexception e) {e.printstacktrace();}}/*** 修改密码* @throws ioexception */public void modifypassword(httprvletrequest req, httprvletrespon resp) throws ioexception {//设置请求编码格式:req.tcharacterencoding("utf-8");//设置响应编码格式resp.tcontenttype("text/html;chart=utf-8");string password = req.getparameter("newpassword");ur ur =(ur) req.getssion().getattribute("ur");int id = ur.getid();int d = rvice.updatepasswordbyid(id, password);try {if(d>0) {jsonresult ok = jsonresult.ok();resp.getwriter().println(jsonutil.javaobjecttojson(ok));}el {jsonresult errormsg = jsonresult.errormsg("修改失败,请重试");resp.getwriter().println(jsonutil.javaobjecttojson(errormsg));}} catch (exception e) {e.printstacktrace();}}/*** 成功修改密码后,清除ssion中的数据,并且重新跳转到登录页* @param req* @param resp*/public void aftermodifypassword(httprvletrequest req, httprvletrespon resp) {req.getssion().removeattribute("ur");try {//使用iframe时,要避免这种直接跳转的方式// 此时只会让内嵌的iframe跳转到登录页,并非整个页面//resp.ndredirect("backstage/login.jsp");printwriter writer = resp.getwriter();writer.print("<html>");writer.print("<script>");writer.print("window.open('"+ req.getcontextpath()+"/backstage/login.jsp','_top')");writer.print("</script>");writer.print("</html>");} catch (ioexception e) {e.printstacktrace();}}/*** 退出登录*/public void logout(httprvletrequest req, httprvletrespon resp) {req.getssion().removeattribute("ur");try {resp.ndredirect("backstage/login.jsp");} catch (ioexception e) {e.printstacktrace();}}}
到此这篇关于java实战玩具商城的前台与后台实现流程的文章就介绍到这了,更多相关java 玩具商城内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!
本文发布于:2023-04-04 09:36:08,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/4b74506aa9d81a6de3a258de4c9f7199.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:Java实战玩具商城的前台与后台实现流程.doc
本文 PDF 下载地址:Java实战玩具商城的前台与后台实现流程.pdf
留言与评论(共有 0 条评论) |