Java 实战练习之网上电商项目的实现
程序员文章站
2022-04-13 08:35:19
一、项目简述本系统功能包括: 一款基于springboot+vue的电商项目,前后端分离项目,前台后台都有,前台商品展示购买,购物车分类,订 单查询等等,后台商品管理,订单管理,信息维护,用户管理等等...
一、项目简述
本系统功能包括: 一款基于springboot+vue的电商项目,前后端分离项目,前台后台都有,前台商品展示购买,购物车分类,订 单查询等等,后台商品管理,订单管理,信息维护,用户管理等等。
二、项目运行
环境配置: jdk1.8 + tomcat8.5 + mysql + hbuilderx (webstorm也 行)+ eclispe (intellij idea,eclispe,myeclispe,sts都支 持)。
项目技术: springboot + maven + mybatis + vue + redis^k, b/s 模式+ maven等等,附带支付宝沙箱环境以及支付环节代码。
商品相关业务代码:
/** * @author qiu * @description 商品相关业务 */ @restcontroller @crossorigin public class productcontroller { final producttypeservice producttypeservice; final productbrandservice productbrandservice; final productservice productservice; public productcontroller(productservice productservice, producttypeservice producttypeservice,productbrandservice productbrandservice) { this.producttypeservice = producttypeservice; this.productbrandservice = productbrandservice; this.productservice = productservice; } /*商品类别*/ @requestmapping(value = "/product/findbyid") private commonresult findbyid(integer productid) { product product = productservice.selectbyid(productid); if(product!=null){ return commonresult.success("商品查询成功",product); }else{ return commonresult.error("商品查询失败"); } } @requestmapping(value = "/product/findbykey") private commonresult findbykey(string productno) { product product = productservice.selectbykey(productno); if(product!=null){ return commonresult.success("商品查询成功",product); }else{ return commonresult.error("商品查询失败"); } } @requestmapping(value = "/product/findidbykey") private commonresult findidbykey(string productno) { integer productid = productservice.selectidbykey(productno); if(productid!=null){ return commonresult.success("商品id查询成功",productid); }else{ return commonresult.error("商品id查询失败"); } } @requestmapping(value = "/product/findcount") private commonresult findcount() { integer count = productservice.selectcount(); if(count!=null){ return commonresult.success("商品数量查询成功",count); }else{ return commonresult.error("商品数量查询失败"); } } @requestmapping(value = "/product/existskey") private commonresult existskey(string productno) { boolean isexist = productservice.existswithprimarykey(productno); if(isexist!=null){ return commonresult.success("商品是否存在查询成功",isexist); }else{ return commonresult.error("商品是否存在查询失败"); } } @requestmapping(value = "/product/existstype") private commonresult existstype(string producttype) { boolean isexist = productservice.existsproducttype(producttype); if(isexist!=null){ return commonresult.success("查询成功",isexist); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/product/existsbrand") private commonresult existsbrand(string productbrand) { boolean isexist = productservice.existsproductbrand(productbrand); if(isexist!=null){ return commonresult.success("查询成功",isexist); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/product/findall") private commonresult findall() { list<product> products = productservice.selectall(); if(products!=null){ return commonresult.success("全部商品信息查询成功",products); }else{ return commonresult.error("全部商品信息查询失败"); } } @requestmapping(value = "/product/findallsale") private commonresult findallsale() { list<product> products = productservice.selectallsale(); if(products!=null){ return commonresult.success("全部商品信息查询成功",products); }else{ return commonresult.error("全部商品信息查询失败"); } } @requestmapping(value = "/product/findalllikename") private commonresult findalllikename(string keyword) { list<product> products = productservice.selectalllikename(keyword); if(products!=null){ return commonresult.success("全部商品信息查询成功",products); }else{ return commonresult.error("全部商品信息查询失败"); } } @requestmapping(value = "/product/findallliketype") private commonresult findallliketype(string keyword) { list<product> products = productservice.selectallliketype(keyword); if(products!=null){ return commonresult.success("全部商品信息查询成功",products); }else{ return commonresult.error("全部商品信息查询失败"); } } @requestmapping(value = "/product/findalllikebrand") private commonresult findalllikebrand(string keyword) { list<product> products = productservice.selectalllikebrand(keyword); if(products!=null){ return commonresult.success("全部商品信息查询成功",products); }else{ return commonresult.error("全部商品信息查询失败"); } } @requestmapping(value = "/product/findallbytype") private commonresult findallbytype() { list<map<string, object>> maps = productservice.selectallbytype(); if(maps!=null){ return commonresult.success("商品分类信息查询成功",maps); }else{ return commonresult.error("商品分类信息查询失败"); } } @requestmapping(value = "/product/add") private commonresult add(product product) { system.out.println(product); if(productservice.insertdata(product)){ return commonresult.success("添加商品成功",product); }else{ return commonresult.error("添加商品失败"); } } @requestmapping(value = "/product/update") private commonresult update(product product) { if(product.getisnew()!=null && product.getisnew()){ product.setsaletime(new date()); } if(productservice.updatebyid(product)){ return commonresult.success("修改商品成功",product); }else{ return commonresult.error("修改商品失败"); } } @requestmapping(value = "/product/delete") private commonresult delete(integer productid) { if(productservice.deletebyid(productid)){ return commonresult.success("商品删除成功","productid:" + productid); }else{ return commonresult.error("商品删除失败"); } } /*商品类别*/ @requestmapping(value = "/producttype/add") private commonresult addtype(producttype producttype) { if(producttypeservice.insertdata(producttype)){ return commonresult.success("商品分类添加成功",producttype); }else{ return commonresult.error("商品分类添加失败"); } } @requestmapping(value = "/producttype/update") private commonresult updatetype(producttype producttype) { if(producttypeservice.updatebyid(producttype)){ return commonresult.success("商品分类修改成功",producttype); }else{ return commonresult.error("商品分类修改失败"); } } @requestmapping(value = "/producttype/deletebyid") private commonresult deletetypebyid(integer typeid) { if(producttypeservice.deletebyid(typeid)){ return commonresult.success("商品分类删除成功","typeid: "+typeid); }else{ return commonresult.error("商品分类删除失败"); } } @requestmapping(value = "/producttype/deletebyname") private commonresult deletetypebyname(string typename) { if(producttypeservice.deletebyname(typename)){ return commonresult.success("商品分类删除成功","typename: "+typename); }else{ return commonresult.error("商品分类删除失败"); } } @requestmapping(value = "/producttype/existstypename") private commonresult existstypename(integer typeid,string typename) { boolean isexist = producttypeservice.existswithtypename(typeid,typename); if(isexist!=null){ return commonresult.success("查询成功",isexist); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/producttype/findall") private commonresult findalltype() { list<producttype> producttypes = producttypeservice.selectall(); if(producttypes!=null){ return commonresult.success("商品分类查询成功",producttypes); }else{ return commonresult.error("商品分类查询失败"); } } @requestmapping(value = "/producttype/findallname") private commonresult findalltypename() { list<string> names = producttypeservice.selectallname(); if(names!=null){ return commonresult.success("商品分类名称查询成功",names); }else{ return commonresult.error("商品分类名称查询失败"); } } /*商品品牌*/ @requestmapping(value = "/productbrand/add") private commonresult addbrand(productbrand productbrand) { if(productbrandservice.insertdata(productbrand)){ return commonresult.success("商品品牌添加成功",productbrand); }else{ return commonresult.error("商品品牌添加失败"); } } @requestmapping(value = "/productbrand/update") private commonresult updatebrand(productbrand productbrand) { if(productbrandservice.updatebyid(productbrand)){ return commonresult.success("商品品牌修改成功",productbrand); }else{ return commonresult.error("商品品牌修改失败"); } } @requestmapping(value = "/productbrand/deletebyid") private commonresult deletebrandbyid(integer brandid) { if(productbrandservice.deletebyid(brandid)){ return commonresult.success("商品品牌删除成功","brandid: "+brandid); }else{ return commonresult.error("商品品牌删除失败"); } } @requestmapping(value = "/productbrand/deletebyname") private commonresult deletebrandbyname(string brandname) { if(productbrandservice.deletebyname(brandname)){ return commonresult.success("商品品牌删除成功","brandname: "+brandname); }else{ return commonresult.error("商品品牌删除失败"); } } @requestmapping(value = "/productbrand/findall") private commonresult findallbrand() { list<productbrand> productbrands = productbrandservice.selectall(); if(productbrands!=null){ return commonresult.success("商品品牌查询成功",productbrands); }else{ return commonresult.error("商品品牌查询失败"); } } @requestmapping(value = "/productbrand/existsbrandname") private commonresult existsbrandname(integer brandid,string brandname) { boolean isexist = productbrandservice.existswithbrandname(brandid,brandname); if(isexist!=null){ return commonresult.success("查询成功",isexist); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/productbrand/findallname") private commonresult findallbrandname() { list<string> names = productbrandservice.selectallname(); if(names!=null){ return commonresult.success("商品品牌名称查询成功",names); }else{ return commonresult.error("商品品牌名称查询失败"); } } }
商品规格、商品与商品规格的关联代码:
/** * @author qiu * @description 商品规格、商品与商品规格的关联 */ @restcontroller @crossorigin public class specscontroller { final specsservice specsservice; final productspecsservice productspecsservice; public specscontroller(specsservice specsservice,productspecsservice productspecsservice) { this.specsservice = specsservice; this.productspecsservice = productspecsservice; } /*根据id查询规格*/ @requestmapping(value = "/specs/findbyid") private commonresult findbyid(integer specsid) { specs specs = specsservice.selectbyid(specsid); if(specs!=null){ return commonresult.success("查询成功",specs); }else{ return commonresult.error("查询失败"); } } /*查询所有规格信息*/ @requestmapping(value = "/specs/findall") private commonresult findallspecs() { list<specs> specs = specsservice.selectall(); if(specs!=null){ return commonresult.success("查询成功",specs); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/specs/existsspecsname") private commonresult existsspecsname(integer specsid, string specsname, string producttype) { boolean isexist = specsservice.existswithspecsname(specsid,specsname,producttype); if(isexist!=null){ return commonresult.success("查询成功",isexist); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/specs/findallbytype") private commonresult findallspecsbytype(string producttype) { list<specs> specs = specsservice.selectallbytype(producttype); if(specs!=null){ return commonresult.success("查询成功",specs); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/specs/add") private commonresult addspecs(specs specs) { if(specs!=null){ if(specsservice.insertdata(specs)){ return commonresult.success("添加成功",specs); }else{ return commonresult.error("添加失败"); } } return commonresult.error("数据不存在"); } @requestmapping(value = "/specs/update") private commonresult updatespecs(specs specs) { if(specsservice.updatebyid(specs)){ return commonresult.success("更新成功",specs); }else{ return commonresult.error("更新失败"); } } @requestmapping(value = "/specs/delete") private commonresult deletespecs(integer specsid) { if(specsservice.deletebyid(specsid)){ return commonresult.success("删除成功",specsid); }else{ return commonresult.error("删除失败"); } } /*商品 与 规格 的关联表*/ /*查询所有商品规格对应信息*/ @requestmapping(value = "/productspecs/findall") private commonresult findall() { list<productspecs> productspecs = productspecsservice.selectall(); if(productspecs!=null){ return commonresult.success("查询成功",productspecs); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/productspecs/findallbyproid") private commonresult findallbyproid(integer productid) { list<string> specsname = productspecsservice.selectallbyproid(productid); if(specsname!=null){ return commonresult.success("查询成功",specsname); }else{ return commonresult.error("查询失败"); } } @requestmapping(value = "/productspecs/add") private commonresult add(productspecs productspecs) { if(productspecs!=null){ if(productspecsservice.insertdata(productspecs)){ return commonresult.success("添加成功",productspecs); }else{ return commonresult.error("添加失败"); } } return commonresult.error("数据不存在"); } @requestmapping(value = "/productspecs/addbatch") private commonresult addbatch(integer productid,integer[] specsids) { system.out.println(productid); system.out.println(arrays.tostring(specsids)); if(specsids!=null){ productspecs productspecs; list<productspecs> productspecslist = new arraylist<>(); for (integer specsid : specsids) { productspecs = new productspecs(); productspecs.setproductid(productid); productspecs.setspecsid(specsid); productspecslist.add(productspecs); } for (productspecs specs : productspecslist) { system.out.println(specs); } if(productspecsservice.insertbatch(productspecslist)){ return commonresult.success("添加成功",productspecslist); }else{ return commonresult.error("添加失败"); } } return commonresult.error("数据不存在"); } @requestmapping(value = "/productspecs/update") private commonresult update(productspecs productspecs) { if(productspecsservice.updatebyid(productspecs)){ return commonresult.success("更新成功",productspecs); }else{ return commonresult.error("更新失败"); } } @requestmapping(value = "/productspecs/delete") private commonresult delete(productspecs productspecs) { if(productspecsservice.deletebyid(productspecs)){ return commonresult.success("删除成功",productspecs); }else{ return commonresult.error("删除失败"); } } }
到此这篇关于java 实战练习之网上电商项目的实现的文章就介绍到这了,更多相关java 网上电商内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: Java之JNDI注入的实现