当前位置:   article > 正文

springboot构建一个完整的响应式电商网站_springboot电商网站模板

springboot电商网站模板

在这里插入图片描述

项目演示:

整体功能

前端部分:

gitee地址:react 完整代码

后端部分:

pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>product-service</artifactId>

	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.9.RELEASE</version>
        <relativePath/>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.4.4</version>
        </dependency>
    </dependencies>
</project>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

控制器代码:

/**
 * @author zxl
 * @date 4/15/22
 */
@RestController
@RequestMapping("/")
public class ProductController {

    private HashSet set = new HashSet();

    //private final AtomicInteger AMOUNT = new AtomicInteger();
    @GetMapping("/products")
    public HashMap products(){
        HashMap result = new HashMap();
        ArrayList list = new ArrayList();
        HashMap data = null;
        for (int i = 0; i < 8; i++) {
            data = new HashMap();
            data.put("id",i+1);
            data.put("imageUrl","https://cdn.chec.io/merchants/19661/assets/VFgCKovPcmNWYm4G|Screenshot 2020-11-25 at 11.01.24.png");
            data.put("name","第"+(i+1)+"个商品");
            data.put("price",45.5+i);
            data.put("description","<p style='color:red;'>商品描述</p>");
            list.add(data);
        }
        result.put("data",list);
        return result;
    }

    @GetMapping("/cart/{productId}/{amount}")
    public HashMap cart(@PathVariable String productId,@PathVariable Integer amount){
        HashMap result = new HashMap();
        //cartItem
        HashMap data = new HashMap();
        data.put("id",productId);
        // data.put("imageUrl","https://cdn.chec.io/merchants/18462/images/676785cedc85f69ab27c42c307af5dec30120ab75f03a9889ab29|u9 1.png");
        data.put("imageUrl","https://cdn.chec.io/merchants/19661/assets/VFgCKovPcmNWYm4G|Screenshot 2020-11-25 at 11.01.24.png");
        data.put("name",productId);
        data.put("price",45.5);
        data.put("description","<p style='color:red;'>商品描述</p>");
        data.put("totalPrice",45.5);
        data.put("quantity",amount);
        result.put("totalPrice",99999);
        set.add(data);
        //cart
        result.put("items",set);
        result.put("total_items",set.size());
        result.put("id",1234);
        return result;
    }

    @PutMapping("/cart/{productId}/{amount}")
    public HashMap updateCart(@PathVariable String productId,@PathVariable Integer amount){
        HashMap result = new HashMap();
        //cartItem
        HashMap data = new HashMap();
        //update cartItem
        for (Object o : set) {
            HashMap item = (HashMap) o;
            if(productId.equals(item.get("id"))){
                item.put("quantity",amount);
            }
        }
        result.put("totalPrice",99999);
        //set.add(data);
        //cart
        result.put("items",set);
        result.put("total_items",set.size());
        result.put("id",1234);
        return result;
    }

    @DeleteMapping("/cart/{productId}")
    public HashMap removeFromCart(@PathVariable String productId){
        HashMap result = new HashMap();
        //cartItem
        //remove item
        Iterator iterator = set.iterator();
        while(iterator.hasNext()){
            HashMap item = (HashMap)iterator.next();
            if(productId.equals(item.get("id"))){
                 iterator.remove();
            }

        }

        result.put("totalPrice",99999);
        result.put("items",set);
        result.put("total_items",set.size());
        result.put("id",1234);
        return result;
    }
    @GetMapping("/carts")
    public HashMap carts(){
        HashMap result = new HashMap();
        result.put("totalPrice",99999);
        result.put("items",set);
        result.put("total_items",set.size());
        result.put("id",1234);
        return result;
    }

    @GetMapping("/carts/empty")
    public HashMap empty(){
        set.clear();
        HashMap result = new HashMap();
        result.put("totalPrice",99999);
        result.put("items",set);
        result.put("total_items",set.size());
        result.put("id",1234);
        return result;
    }

    @PostMapping("/carts/checkout")
    public HashMap checkout(@RequestBody  Shipping shipping){
        HashMap data = new HashMap();
        data.put("customer",shipping);
        set.clear();
        return data;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121

application.yml

server:
  port: 19090
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/143819
推荐阅读
相关标签