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

 更新时间:2021年11月12日 16:09:28   作者:qq_1334611189  
读万卷书不如行万里路,只学书上的理论是远远不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用java+vue+Springboot+ssm+mysql+maven+redis实现一个网上电商项目,大家可以在过程中查缺补漏,提升水平

一、项目简述

本系统功能包括: 一款基于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实现双色球机选号码生成器

    java实现双色球机选号码生成器

    这篇文章主要为大家详细介绍了java实现双色球机选号码生成器,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-01-01
  • Spring @Conditional注解示例详细讲解

    Spring @Conditional注解示例详细讲解

    @Conditional是Spring4新提供的注解,它的作用是按照一定的条件进行判断,满足条件给容器注册bean,这篇文章主要介绍了Spring @Conditional注解示例详细讲解,需要的朋友可以参考下
    2022-11-11
  • Springboot 接口需要接收参数类型是数组问题

    Springboot 接口需要接收参数类型是数组问题

    这篇文章主要介绍了Springboot 接口需要接收参数类型是数组问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-01-01
  • MyBatis框架中mybatis配置文件详细介绍

    MyBatis框架中mybatis配置文件详细介绍

    这篇文章主要介绍了MyBatis框架中mybatis配置文件详细介绍,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2018-01-01
  • Spring Boot 配置随机数的技巧代码详解

    Spring Boot 配置随机数的技巧代码详解

    这篇文章主要介绍了Spring Boot 配置随机数技巧,spring boot 支持在系统加载的时候配置随机数,具体实例代码大家参考下本文
    2018-05-05
  • 详解Spring通过@Value注解注入属性的几种方式

    详解Spring通过@Value注解注入属性的几种方式

    本篇文章主要介绍了详解Spring通过@Value注解注入属性的几种方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
    2017-03-03
  • Java接入支付宝授权第三方登录的完整步骤

    Java接入支付宝授权第三方登录的完整步骤

    不管是支付宝支付,还是微信支付,还是银联支付等,大部分的支付流程都是相似的,这篇文章主要给大家介绍了关于Java接入支付宝授权第三方登录的相关资料,使用支付宝的沙盒环境示例,需要的朋友可以参考下
    2021-07-07
  • Springboot2.X集成redis集群(Lettuce)连接的方法

    Springboot2.X集成redis集群(Lettuce)连接的方法

    这篇文章主要介绍了Springboot2.X集成redis集群(Lettuce)连接的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-07-07
  • 了解Java多线程的可见性与有序性

    了解Java多线程的可见性与有序性

    这篇文章主要介绍了了解Java多线程的可见性与有序性,在Java内存模型中,允许编译器和处理器对指令进行重排序,但是重排序过程不会影响到单线程程序的执行,却会影响到多线程并发执行的正确性。,需要的朋友可以参考下
    2019-06-06
  • SpringBoot2.x 整合Spring-Session实现Session共享功能

    SpringBoot2.x 整合Spring-Session实现Session共享功能

    这篇文章主要介绍了SpringBoot2.x 整合Spring-Session实现Session共享功能,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-07-07

最新评论