Java 仿天猫服装商城系统的实现流程
程序员文章站
2022-03-10 13:22:01
一、项目简述功能:网上商城系统,前台+后台管理,用户注册,登录, 上哦展示,分组展示,搜索,收货地址管理,购物车管 理,添加,购买,个人信息修改。订单查询等等,后台商 品管理,分类管理,库存管理,订单...
一、项目简述
功能:网上商城系统,前台+后台管理,用户注册,登录, 上哦展示,分组展示,搜索,收货地址管理,购物车管 理,添加,购买,个人信息修改。订单查询等等,后台商 品管理,分类管理,库存管理,订单管理,用户管理,信 息、修改等等。
二、项目运行
环境配置: jdk1.8 + tomcat8.5 + mysql + eclispe (intellij idea,eclispe,myeclispe,sts 都支持)
项目技术: jsp +spring + springmvc + mybatis + html+ css + javascript + jquery + ajax + layui+ maven等等。
权限控制代码:
/** * 产品详情页 */ @controller public class foreproductdetailscontroller extends basecontroller { @resource(name = "productservice") private productservice productservice; @resource(name = "userservice") private userservice userservice; @resource(name = "productimageservice") private productimageservice productimageservice; @resource(name = "categoryservice") private categoryservice categoryservice; @resource(name = "propertyvalueservice") private propertyvalueservice propertyvalueservice; @resource(name = "propertyservice") private propertyservice propertyservice; @resource(name = "reviewservice") private reviewservice reviewservice; @resource(name = "productorderitemservice") private productorderitemservice productorderitemservice; //转到前台天猫-产品详情页 @requestmapping(value = "product/{pid}", method = requestmethod.get) public string gotopage(httpsession session, map<string, object> map, @pathvariable("pid") string pid /*产品id*/) { logger.info("检查用户是否登录"); object userid = checkuser(session); if (userid != null) { logger.info("获取用户信息"); user user = userservice.get(integer.parseint(userid.tostring())); map.put("user", user); } logger.info("获取产品id"); integer product_id = integer.parseint(pid); logger.info("获取产品信息"); product product = productservice.get(product_id); if (product == null || product.getproduct_isenabled() == 1) { return "redirect:/404"; } logger.info("获取产品子信息-分类信息"); product.setproduct_category(categoryservice.get(product.getproduct_category().getcategory_id())); logger.info("获取产品子信息-预览图片信息"); list<productimage> singleproductimagelist = productimageservice.getlist(product_id, (byte) 0, null); product.setsingleproductimagelist(singleproductimagelist); logger.info("获取产品子信息-详情图片信息"); list<productimage> detailsproductimagelist = productimageservice.getlist(product_id, (byte) 1, null); product.setdetailproductimagelist(detailsproductimagelist); logger.info("获取产品子信息-产品属性值信息"); list<propertyvalue> propertyvaluelist = propertyvalueservice.getlist(new propertyvalue().setpropertyvalue_product(product), null); logger.info("获取产品子信息-分类信息对应的属性列表"); list<property> propertylist = propertyservice.getlist(new property().setproperty_category(product.getproduct_category()), null); logger.info("属性列表和属性值列表合并"); for (property property : propertylist) { for (propertyvalue propertyvalue : propertyvaluelist) { if (property.getproperty_id().equals(propertyvalue.getpropertyvalue_property().getproperty_id())) { list<propertyvalue> property_value_item = new arraylist<>(1); property_value_item.add(propertyvalue); property.setpropertyvaluelist(property_value_item); break; } } } logger.info("获取产品子信息-产品评论信息"); product.setreviewlist(reviewservice.getlistbyproductid(product_id, null)); if (product.getreviewlist() != null) { for (review review : product.getreviewlist()) { review.setreview_user(userservice.get(review.getreview_user().getuser_id())); } } logger.info("获取猜你喜欢列表"); integer category_id = product.getproduct_category().getcategory_id(); integer total = productservice.gettotal(new product().setproduct_category(new category().setcategory_id(category_id)), new byte[]{0, 2}); logger.info("分类id为{}的产品总数为{}条", category_id, total); //生成随机数 int i = new random().nextint(total); if (i + 2 >= total) { i = total - 3; } if (i < 0) { i = 0; } list<product> loveproductlist = productservice.getlist(new product().setproduct_category( new category().setcategory_id(category_id)), new byte[]{0, 2}, null, new pageutil().setcount(3).setpagestart(i) ); if (loveproductlist != null) { logger.info("获取产品列表的相应的一张预览图片"); for (product loveproduct : loveproductlist) { loveproduct.setsingleproductimagelist(productimageservice.getlist(loveproduct.getproduct_id(), (byte) 0, new pageutil(0, 1))); } } logger.info("获取分类列表"); list<category> categorylist = categoryservice.getlist(null, new pageutil(0, 3)); map.put("loveproductlist", loveproductlist); map.put("categorylist", categorylist); map.put("propertylist", propertylist); map.put("product", product); map.put("guessnumber", i); map.put("pageutil", new pageutil(0, 10).settotal(product.getproduct_review_count())); logger.info("转到前台-产品详情页"); return "fore/productdetailspage"; } //按产品id加载产品评论列表-ajax @deprecated @responsebody @requestmapping(value = "review/{pid}", method = requestmethod.get, produces = "application/json;charset=utf-8") public string loadproductreviewlist(@pathvariable("pid") string pid/*产品id*/, @requestparam integer index/* 页数 */, @requestparam integer count/* 行数 */) { logger.info("获取产品id"); integer product_id = integer.parseint(pid); logger.info("获取产品评论列表"); list<review> reviewlist = reviewservice.getlistbyproductid(product_id, new pageutil(index, count)); jsonobject jsonobject = new jsonobject(); jsonobject.put("reviewlist", jsonarray.parsearray(json.tojsonstring(reviewlist))); return jsonobject.tojsonstring(); } //按产品id加载产品属性列表-ajax @deprecated @responsebody @requestmapping(value = "property/{pid}", method = requestmethod.get, produces = "application/json;charset=utf-8") public string loadproductpropertylist(@pathvariable("pid") string pid/*产品id*/) { logger.info("获取产品id"); integer product_id = integer.parseint(pid); logger.info("获取产品详情-属性值信息"); product product = new product(); product.setproduct_id(product_id); list<propertyvalue> propertyvaluelist = propertyvalueservice.getlist(new propertyvalue().setpropertyvalue_product(product), null); logger.info("获取产品详情-分类信息对应的属性列表"); list<property> propertylist = propertyservice.getlist(new property().setproperty_category(product.getproduct_category()), null); logger.info("属性列表和属性值列表合并"); for (property property : propertylist) { for (propertyvalue propertyvalue : propertyvaluelist) { if (property.getproperty_id().equals(propertyvalue.getpropertyvalue_property().getproperty_id())) { list<propertyvalue> property_value_item = new arraylist<>(1); property_value_item.add(propertyvalue); property.setpropertyvaluelist(property_value_item); break; } } } jsonobject jsonobject = new jsonobject(); jsonobject.put("propertylist", jsonarray.parsearray(json.tojsonstring(propertylist))); return jsonobject.tojsonstring(); } //加载猜你喜欢列表-ajax @responsebody @requestmapping(value = "guess/{cid}", method = requestmethod.get, produces = "application/json;charset=utf-8") public string guessyoulike(@pathvariable("cid") integer cid, @requestparam integer guessnumber) { logger.info("获取猜你喜欢列表"); integer total = productservice.gettotal(new product().setproduct_category(new category().setcategory_id(cid)), new byte[]{0, 2}); logger.info("分类id为{}的产品总数为{}条", cid, total); //生成随机数 int i = new random().nextint(total); if (i + 2 >= total) { i = total - 3; } if (i < 0) { i = 0; } while (i == guessnumber) { i = new random().nextint(total); if (i + 2 >= total) { i = total - 3; } if (i < 0) { i = 0; break; } } logger.info("guessnumber值为{},新guessnumber值为{}", guessnumber, i); list<product> loveproductlist = productservice.getlist(new product().setproduct_category( new category().setcategory_id(cid)), new byte[]{0, 2}, null, new pageutil().setcount(3).setpagestart(i) ); if (loveproductlist != null) { logger.info("获取产品列表的相应的一张预览图片"); for (product loveproduct : loveproductlist) { loveproduct.setsingleproductimagelist(productimageservice.getlist(loveproduct.getproduct_id(), (byte) 0, new pageutil(0, 1))); } } jsonobject jsonobject = new jsonobject(); logger.info("获取数据成功!"); jsonobject.put("success", true); jsonobject.put("loveproductlist", jsonarray.parsearray(json.tojsonstring(loveproductlist))); jsonobject.put("guessnumber", i); return jsonobject.tojsonstring(); } }
用户信息管理控制层:
/** * 用户信息管理 */ @controller public class foreusercontroller extends basecontroller{ @resource(name = "addressservice") private addressservice addressservice; @resource(name="userservice") private userservice userservice; //转到前台天猫-用户详情页 @requestmapping(value = "userdetails", method = requestmethod.get) public string gotouserdetail(httpsession session, map<string,object> map){ logger.info("检查用户是否登录"); object userid = checkuser(session); if (userid != null) { logger.info("获取用户信息"); user user = userservice.get(integer.parseint(userid.tostring())); map.put("user", user); logger.info("获取用户所在地区级地址"); string districtaddressid = user.getuser_address().getaddress_areaid(); address districtaddress = addressservice.get(districtaddressid); logger.info("获取市级地址信息"); address cityaddress = addressservice.get(districtaddress.getaddress_regionid().getaddress_areaid()); logger.info("获取其他地址信息"); list<address> addresslist = addressservice.getroot(); list<address> citylist = addressservice.getlist( null,cityaddress.getaddress_regionid().getaddress_areaid() ); list<address> districtlist = addressservice.getlist(null,cityaddress.getaddress_areaid()); map.put("addresslist", addresslist); map.put("citylist", citylist); map.put("districtlist", districtlist); map.put("addressid", cityaddress.getaddress_regionid().getaddress_areaid()); map.put("cityaddressid", cityaddress.getaddress_areaid()); map.put("districtaddressid", districtaddressid); return "fore/userdetails"; } else { return "redirect:/login"; } } //前台天猫-用户更换头像 @responsebody @requestmapping(value = "user/uploaduserheadimage", method = requestmethod.post, produces = "application/json;charset=utf-8") public string uploaduserheadimage(@requestparam multipartfile file, httpsession session ){ string originalfilename = file.getoriginalfilename(); logger.info("获取图片原始文件名:{}", originalfilename); string extension = originalfilename.substring(originalfilename.lastindexof('.')); string filename = uuid.randomuuid() + extension; string filepath = session.getservletcontext().getrealpath("/") + "res/images/item/userprofilepicture/" + filename; logger.info("文件上传路径:{}", filepath); jsonobject jsonobject = new jsonobject(); try { logger.info("文件上传中..."); file.transferto(new file(filepath)); logger.info("文件上传成功!"); jsonobject.put("success", true); jsonobject.put("filename", filename); } catch (ioexception e) { logger.warn("文件上传失败!"); e.printstacktrace(); jsonobject.put("success", false); } return jsonobject.tojsonstring(); } //前台天猫-用户详情更新 @requestmapping(value="user/update",method=requestmethod.post,produces ="application/json;charset=utf-8") public string userupdate(httpsession session, map<string,object> map, @requestparam(value = "user_nickname") string user_nickname /*用户昵称 */, @requestparam(value = "user_realname") string user_realname /*真实姓名*/, @requestparam(value = "user_gender") string user_gender /*用户性别*/, @requestparam(value = "user_birthday") string user_birthday /*用户生日*/, @requestparam(value = "user_address") string user_address /*用户所在地 */, @requestparam(value = "user_profile_picture_src", required = false) string user_profile_picture_src /* 用户头像*/, @requestparam(value = "user_password") string user_password/* 用户密码 */ ) throws parseexception, unsupportedencodingexception { logger.info("检查用户是否登录"); object userid = checkuser(session); if (userid != null) { logger.info("获取用户信息"); user user = userservice.get(integer.parseint(userid.tostring())); map.put("user", user); } else { return "redirect:/login"; } logger.info("创建用户对象"); if (user_profile_picture_src != null && "".equals(user_profile_picture_src)) { user_profile_picture_src = null; } user userupdate = new user() .setuser_id(integer.parseint(userid.tostring())) .setuser_nickname(user_nickname) .setuser_realname(user_realname) .setuser_gender(byte.valueof(user_gender)) .setuser_birthday(new simpledateformat("yyyy-mm-dd").parse(user_birthday)) .setuser_address(new address().setaddress_areaid(user_address)) .setuser_profile_picture_src(user_profile_picture_src) .setuser_password(user_password); logger.info("执行修改"); if (userservice.update(userupdate)){ logger.info("修改成功!跳转到用户详情页面"); return "redirect:/userdetails"; } throw new runtimeexception(); } }
地址信息管理控制层:
/** * 地址信息管理 */ @restcontroller public class foreaddresscontroller extends basecontroller { @resource(name = "addressservice") private addressservice addressservice; //根据address_areaid获取地址信息-ajax @requestmapping(value = "address/{areaid}", method = requestmethod.get, produces = "application/json;charset=utf-8") protected string getaddressbyareaid(@pathvariable string areaid) { jsonobject object = new jsonobject(); logger.info("获取areaid为{}的地址信息"); list<address> addresslist = addressservice.getlist(null, areaid); if (addresslist == null || addresslist.size() <= 0) { object.put("success", false); return object.tojsonstring(); } logger.info("获取该地址可能的子地址信息"); list<address> childaddresslist = addressservice.getlist(null, addresslist.get(0).getaddress_areaid()); object.put("success", true); object.put("addresslist", addresslist); object.put("childaddresslist", childaddresslist); return object.tojsonstring(); } }
到此这篇关于java 仿天猫服装商城系统的实现流程的文章就介绍到这了,更多相关java 商城系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!