Java 实战练习之网上电商项目的实现

一、项目简述

本系统功能包括: 一款基于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 网上电商内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • Java 实战项目锤炼之网上花店商城的实现流程

    一.项目简述 功能: 一套完整的网上花店商场系统,系统支持前台会员的注册 登陆系统留言,花朵的品种选择,详情浏览,加入购物 车,购买花朵等:后台支持管理员的花朵种类添加,花朵 详情的添加修改,用户管理,留言管理,商场新闻管理等. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP + Servlert + html+ css + JavaScri

  • Java 实战项目锤炼之在线购书商城系统的实现流程

    一.项目简述 功能:一个基于JavaWeb的网上书店的设计与实现,归纳 出了几个模块,首先是登录注册模块,图书查找模块,购 物车模块,订单模块,个人中心模块,用户管理模块,图 书管理模块等. 该项目是javaJeb技术的实战操作,采用了MVC设计模 式,包括基本的entity, jscript, servlet,以及ajax异步请 求,查询分页,持久化层方法的封装等等,对javaweb技 术的巩固很有帮助,为J2EE的学习打下基础,适用于课程 设计,毕业设计. 二.项目运行 环境配置: Jdk1

  • Java 实战项目锤炼之仿天猫网上商城的实现流程

    一.项目简述 功能: 前台: * 用户模块 * 分类模块 * 商品模块 * 购物车模块 * 订单模块 后台: * 管理员模块 * 分类管理模块 * 商品管理模块 * 订单模块 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP + C3P0+ Servlert + html+ css + JavaScript + JQuery + Ajax +

  • Java 实战项目锤炼之在线蛋糕商城系统的实现

    一.项目简述 功能: 主页显示热销商品:所有蛋糕商品展示,可进行商品搜 索:点击商品进入商品详情页,具有立即购买和加入购物 车功能,可增减购买商品数量亦可手动输入(同时验证库 存),热销商品展示.立即购买进入确认订单页面,可选择 已经添加的地址,亦可新增地址.(同时验证库存),可选 择购买哪些商品,可删除不需要的商品.点击结算进入确 认订单页面,确认后提交订单.后台管理:(修改密码 等),商品管理(商品批量添加.上下架等),订单管理. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.

  • Java 实战项目锤炼之网上商城系统的实现流程

    一.项目简述(+需求文档+PPT) 功能: 主页显示热销商品:所有商品展示,可进行商品搜索:点 击商品进入商品详情页,显示库存,具有立即购买和加入 购物车功能,可增减购买商品数量亦可手动输入(同时验证 库存),热销商品展示.立即购买进入确认订单页面,可选 择已经添加的地址,亦可新增地址.(同时验证库存),可 选择购买哪些商品,可删除不需要的商品.点击结算进入 确认订单页面,确认后提交订单,订单重复提交给予响 应,库存不足或商品下架给予响应.后台管理:(修改密码 等),商品管理(商品批量添加.上下

  • Java 实战项目之家居购物商城系统详解流程

    一.项目简述 功能: Java Web精品项目源码,家居商城分类展示,商品展示, 商品下单,购物车,个人中心,后台管理,用户管理,商品管理,分类管理等等. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: Jdbc+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload 打开订单列

  • Java 实战练习之网上电商项目的实现

    一.项目简述 本系统功能包括: 一款基于Springboot+Vue的电商项目,前后端分离项目,前台后台都有,前台商品展示购买,购物车分类,订 单查询等等,后台商品管理,订单管理,信息维护,用户管理等等. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持). 项目技术: Springboot + Maven + My

  • Vue实现商品飞入购物车效果(电商项目)

    各位掘友,好久不见,最近利用工作之余开源了Vue电商项目,高仿某知名O2O买菜平台,整个项目做下来收获还是蛮多的,可以扫描下方二维码体验,本篇是项目的核心知识拆解篇,主要是拆解增加商品飞入购物车的实现过程. 点我体验 项目开源地址 感谢点星+收藏 首先我先简单的介绍下本项目所用到的技术栈: 整个项目采用 vue-cli3 脚手架搭建, Vue全家桶(vue.vuex.vue-router) . Vant UI框架 以及很多著名好用的第三方库如: axios . fastclick . bette

  • Java 实战项目锤炼之网上图书馆管理系统的实现流程

    一.项目简述 功能: 区分为管理员用户和普通用户,普通用户:用户登录,个 人信息修改,图书查询,用户借阅,用户归还,管理员用 户:图书馆里,归还管理,借阅信息查询,图书维护,分 类管理,读者管理等等功能. 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: JSP + Servlert + html+ css + JavaScript + JQuery

  • 基于SpringBoot构建电商秒杀项目代码实例

    一.项目功能概述 电商秒杀需要完成的3个功能: 1.展示一个商品列表页面,我们可以从中看到可秒杀的商品列表 2.点击进入商品详情页,获取该商品的详细信息 3.秒杀时间开始后,点击进入下单确认页面,并支付成功 二.基于SpringBoot进行项目环境搭建 步骤1:创建一个maven工程,使用quickStart骨架. 步骤2:在pom.xml导入SpringBoot相关依赖. <?xml version="1.0" encoding="UTF-8"?> &

  • Vue 电商后台管理项目阶段性总结(推荐)

    一.阶段总结 该项目偏向前端更多一点,后端 API 服务是已经搭建好了的,我们只需要用既可以,(但是作为一个 全栈开发人员,它的数据库的表设计,Restful API 的设计是我们要着重学习的!!!) 这个vue 项目是从 2020 4月开始,一直开发直至 5月23日 部署上线,也算是我的第二个 vue 的实战项目(其实是熟悉 elementUI 的使用),在开发过程中使用 Vue cil4 脚手架进行开发,使用码云作为 Git 管理仓库, 目前已经基本开发完毕,在服务器上也能够正常运行 (ng

  • Java 实战范例之精美网上音乐平台的实现

    一.项目简述 本系统功能包括: 音乐播放 用户登录注册 用户信息编辑.头像修改 歌曲.歌单搜索 歌单打分 歌单.歌曲评论 歌单列表.歌手列表分页显示 歌词同步显不 音乐收藏.下载.拖动控制.音粉制 后台对用户.歌曲.歌手.歌单信息的管理 二.项目运行 环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持). 项目技术: Springb

随机推荐