【JavaWeb程序设计】JSP实现购物车功能

news2024/11/29 2:52:25

目录

一、结合之前所学的相关技术,编写代码实现以下购物车功能

1. 我实现的功能运行截图如下

(1)商品列表页面home.jsp

 (2)登录账号页面/未登录点击结账页面

(3)重新登录页面(记住上次登录的用户名和密码)

(4)点击任意商品加入购物车之后查看购物车

2. 数据库test存放的表格

(1)user表

(2)product表

3. 实体类

(1)User

(2)Product.java

4. CartController.java

5. JSP页面

(1)展现商品列表(home.jsp)

(2)登陆页面(login.jsp)

(3)登录后台处理页面(loginAction.jsp)

(4)结账页面(checkout.jsp)

(5)购物车页面(cart.jsp)


一、结合之前所学的相关技术,编写代码实现以下购物车功能

1. 编写一个页面,展现商品列表(静态页面),页面右上方有登陆、结账和查看购物车三个按钮,下方展示网站历史访问的人数

2. 用户点击商品后,可以将商品加入购物车

3. 用户点击登陆,跳转到登陆页面

4. 用户点击结账,若已登陆跳转至结账页面,否则跳转到登陆页面登陆后再跳转到结账页。

5. 用户点击查看购物车按钮,跳转至购物车页面,可查看购物车列表、增加商品数量或者删除商品

1. 我实现的功能运行截图如下

(1)商品列表页面home.jsp

 (2)登录账号页面/未登录点击结账页面

(3)重新登录页面(记住上次登录的用户名和密码)

(4)点击任意商品加入购物车之后查看购物车

 (5)增加或减少商品

(6)商品数量减为0时移除

(7)点击去结算,展示总金额

2. 数据库test存放的表格

(1)user表

(2)product表

导入jar包 

3. 实体类

(1)User

package com.ryx.web.sy7;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class User {
    private String username;
    private String password;
}

(2)Product.java

package com.ryx.web.sy7;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Product {
    Integer id;
    String name;
    String imagePath;
    BigDecimal price;
    String description;
}

(3)ProductVo

package com.ryx.web.sy7;

import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;

public class ProductVo extends Product {
    @Getter
    @Setter
    Integer count; //统计数量

    public ProductVo(Integer id, Integer count, String name, double price, String imagePath) {
        super();
        this.id = id;
        this.count = count;
        this.name = name;
        this.price = BigDecimal.valueOf(price);
        this.imagePath=imagePath;
    }
}

4. CartController.java

package com.ryx.web.sy7;

import lombok.SneakyThrows;
import org.springframework.util.ObjectUtils;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "shoppingCart", value = "/shoppingCart")
public class CartController extends HttpServlet {
//    连接数据库
    private static final String DB_URL = "jdbc:mysql://localhost:3306/test";
    private static final String DB_USERNAME = "root";
    private static final String DB_PASSWORD = "abc1234";

    @SneakyThrows
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        String op = request.getParameter("op");
        String whereCome = request.getHeader("Referer");
        String redirectPath = null;
//        如果在主页点击加入购物车超链接,不跳转
        if (whereCome.equals("http://localhost:8080/sy7/home.jsp")) {
            redirectPath = request.getContextPath() + "/sy7/home.jsp";
        } else {
//            如果在购物车页面增加或删除商品也不跳转
            redirectPath = request.getContextPath() + "/sy7/cart.jsp";
        }
        HttpSession session = request.getSession();
        Map<Integer, ProductVo> cart = (Map<Integer, ProductVo>) session.getAttribute("cart");
        if (ObjectUtils.isEmpty(cart)) {
            cart = new HashMap();
        }
        switch (op) {
//            添加商品
            case "add":
                if (!ObjectUtils.isEmpty(cart.get(id))) {
                    ProductVo productVo = cart.get(id);
                    productVo.setCount(productVo.getCount() + 1);
                    cart.put(id, productVo);
                } else {
                    Class.forName("com.mysql.jdbc.Driver");
                    try (Connection conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD)) {
                        String query = "SELECT * FROM product WHERE id = ?";
                        try (PreparedStatement stmt = conn.prepareStatement(query)) {
                            stmt.setInt(1, id);
                            try (ResultSet rs = stmt.executeQuery()) {
                                if (rs.next()) {
                                    String name = rs.getString("name");
                                    double price = rs.getDouble("price");
                                    String imagePath = rs.getString("image_path");
                                    Integer iid = rs.getInt("id");
                                    ProductVo productVo = new ProductVo(iid, 1, name, price, imagePath);
                                    cart.put(id, productVo);
                                }
                            }
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
                break;
//          减少商品
            case "sub":
                if (!ObjectUtils.isEmpty(cart.get(id))) {
                    ProductVo productVo = cart.get(id);
//                    防止出现负数
                    if (productVo.getCount() > 1) {
                        productVo.setCount(productVo.getCount() - 1);
                        cart.put(id, productVo);
                    } else {
//                        如果小于1则移除商品
                        cart.remove(id);
                    }

                }
                break;
        }
        session.setAttribute("cart", cart);
        response.sendRedirect(redirectPath);
    }
}

5. JSP页面

(1)展现商品列表(home.jsp)

CSS

table {
    border-collapse: collapse;
    width: 86%;
}

table, th, td {
    border: 1px solid gainsboro;
}

td {
    width: 200px;
}

.redText {
    color: #FF0000;
}

.pinkTest {
    color: lightpink;
}
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<%--
  Created by IntelliJ IDEA.
  User: 86189
  Date: 2023/10/23
  主页面展示商品
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>小煊的美妆铺</title>
   
</head>
<body>
<h1 align="center" class="pinkTest">欢迎来到小煊的美妆铺~</h1>
<div align="right" style="width: 90%"><a href="login.jsp">登录</a></div>
<div align="right" style="width: 90%"><a href="checkout.jsp">结算</a></div>
<div align="right" style="width: 90%"><a href="cart.jsp">查看购物车</a></div>
<br>

<table align="center">
    <%---------------------- 获取商品数据 -----------------------------%>
    <%
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            //连接数据库
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "abc1234");
            String query = "SELECT * FROM product";
            stmt = conn.prepareStatement(query);
            rs = stmt.executeQuery();

            int count = 0;
            while (rs.next()) {
                int id = rs.getInt("id"); //商品编号
                String name = rs.getString("name"); //商品名
                double price = rs.getDouble("price"); //价格
                String description = rs.getString("description"); //描述
                String imagePath = rs.getString("image_path"); // 图片路径
                //五个商品即换行
                if (count % 5 == 0) {
                    out.println("<tr>");
                }
    %>
    <td><br>
        <%--------------------------图片-----------------------%>
        <div align="center"><img src="<%=request.getContextPath()+imagePath%>" width="180px" height="240px"></div>
        <%--------------------------商品描述-----------------------%>
        <div> <%=name%><%=description%> </div>
        <%--------------------------价格-----------------------%>
        <div class="redText" align="left"> ¥:<%=price%> </div>
        <%--------------------------加购-----------------------%>
        <div align="right">
            <form action="home.jsp" method="post">
                <button onclick="void(0)"><a style="text-decoration: none"
                                             href="<%=request.getContextPath()+"/shoppingCart?id="+id+"&op=add"%>"/>加入购物车
                </button>
            </form>
        </div>
    </td>
    <%
                //闭合标签
                if (count % 5 == 4) {
                    out.println("</tr>");
                }
                count++;
            }
            //最后不足五个,自动闭合
            if (count % 5 != 0) {
                out.println("</tr>");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
            } catch (Exception e) {
            }
            try {
                stmt.close();
            } catch (Exception e) {
            }
            try {
                conn.close();
            } catch (Exception e) {
            }
        }
    %>
</table>
<br>
<%
//    初始化历史访问人数
    Integer accessCount = (Integer) session.getAttribute("accessCount");
    if (accessCount == null) {
        accessCount = new Integer(0);
    } else {
        accessCount = new Integer(accessCount.intValue() + 1);
    }
    session.setAttribute("accessCount", accessCount);
%>

<div>历史访问人数:<%= accessCount %> </div>
</body>
</html>

(2)登陆页面(login.jsp)

JSP程序段+JS代码

<%-----------------------JSP程序段---------------------------%>
<%
    request.setCharacterEncoding("UTF-8");
    //一次性登录
    String msg = request.getParameter("msg");
%>
<%
    if (msg != null) {
        String errorMessage = "账号或密码有误,请重新输入!";
%>
<script>
    var error = '<%= errorMessage %>';
    alert(error);
</script>
<%
    }
%>

<%-- 读取Cookie --%>
<%
    Cookie[] cookies = request.getCookies();
    String savedUsername = null;
    String savedPassword = null;

    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("username")) {
                savedUsername = cookie.getValue();
            } else if (cookie.getName().equals("password")) {
                savedPassword = cookie.getValue();
            }
        }
    }
%>

HTML

<%--
  Created by IntelliJ IDEA.
  User: 86189
  Date: 2023/10/13
  登录页面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <style>
        body {
            display: flex;
            justify-content: center;
            padding-top: 40px;
        }
        .titlecolor{
            color: lightpink;
        }
    </style>
    <title>登录页面</title>
</head>
<body>
<%-----------------------登录表单--------------------------%>
<form action="loginAction.jsp" method="post">
    <h1 align="center" class="titlecolor">登录账号</h1>
    <br>
    <table width="300px">
        <tr>
            <td>
                <laber for="username">用户名:</laber>
            </td>
            <td><input type="text" value="<%= savedUsername==null?"":savedUsername%>" id="username" name="username" required></td>
        </tr>
        <tr>
            <td><label for="password">密码:</label></td>
            <td><input type="password" value="<%= savedPassword==null?"":savedPassword%>" id="password" name="password" required></td>
            <td align="right"><input type="submit" value="登录"></td>
        </tr>
        <tr>
            <td></td>
           <td><input type="checkbox" name="remember" value="member">记住密码</td>
        </tr>
    </table>
</form>

</body>
</html>

(3)登录后台处理页面(loginAction.jsp)

<%@ page import="com.ryx.web.sy7.User" %>
<%@ page import="java.sql.*" %>
<%--
  Created by IntelliJ IDEA.
  User: 86189
  Date: 2023/10/13
  判断输入的用户信息是否存在数据库
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%!
    public boolean validateUser(String username, String password) {
        // 使用JDBC连接数据库
        Connection connection = null;
        PreparedStatement statement = null;
        ResultSet resultSet = null;

        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/test";  //数据库
        String user = "root"; //账户
        String psword = "abc1234"; //密码

        try {
            try {
                try {
                    Class.forName(driver);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
                // 获取数据库连接
                connection = DriverManager.getConnection(url, user, psword);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            try {
                // 构造查询语句
                String query = "SELECT * FROM test.user WHERE username =  ? ";

                // 创建PreparedStatement对象,并设置参数
                statement = connection.prepareStatement(query);
                statement.setString(1, username);

                // 执行查询
                resultSet = statement.executeQuery();
                // 验证用户名和密码
                if (resultSet.next()) {
                    String storedPassword = resultSet.getString("password");
                    if (storedPassword.equals(password)) {
                        return true;
                    }
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }

        } finally {
            // 关闭连接和释放资源
            try {
                if (resultSet != null) {
                    resultSet.close();
                }
                if (statement != null) {
                    statement.close();
                }
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return false;
    }
 %>

<%
    request.setCharacterEncoding("UTF-8");
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    boolean isValidUser = validateUser(username, password);
    //验证成功
    if (isValidUser) {
        // 创建形 Builder 构造者模式,链式编程
        User user = User.builder()
                    .username(username)
                    .password(password)
                    .build();

        String remember = request.getParameter("remember");

        if (remember != null && remember.equals("member")) {
            // 创建存储用户名和密码的Cookie对象
            Cookie usernameCookie = new Cookie("username", username);
            Cookie passwordCookie = new Cookie("password", password);

            // 设置Cookie的有效期(设置为7天)
            usernameCookie.setMaxAge(7 * 24 * 60 * 60); // 7天
            passwordCookie.setMaxAge(7 * 24 * 60 * 60); // 7天

            // 将Cookie添加到响应中
            response.addCookie(usernameCookie);
            response.addCookie(passwordCookie);
        } else {
            // 删除之前保存的Cookie
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals("username") || cookie.getName().equals("password")) {
                        cookie.setMaxAge(0); // 设置有效期为0,即立即删除
                        response.addCookie(cookie);
                    }
                }
            }
        }

        session.setAttribute("user", user);
        //跳转到其他页面
        response.sendRedirect("home.jsp");
    } else {
        //验证失败,提示出错
        response.sendRedirect("login.jsp?msg=failed");
    }
 %>

(4)结账页面(checkout.jsp)

HTML+JSP+JSTL

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.ryx.web.sy7.User" %>
<%@ page import="java.util.Map" %>
<%--
  Created by IntelliJ IDEA.
  User: 86189
  Date: 2023/10/21
  结算页面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<%--------------------判断用户是否登录-----------------------%>
<%
    //存储变量
    User user = (User) session.getAttribute("user");
    //    未登录用户跳转到登录页面
    if (user == null) {
        response.sendRedirect("login.jsp");
    }
%>
<head>
    <meta charset="UTF-8">
    <title>结算</title>
</head>
<body>
<%----------------- 获取购物车中的商品 ------------------------%>
<h1 align="center" style="color: lightpink">订单信息</h1>
<%
    session = request.getSession();
    Map<Integer, Integer> cart = (Map<Integer, Integer>) session.getAttribute("cart");
    if (cart == null) {
        out.println("购物车为空");
        return;
    }
%>
<%--计算总价钱--%>
<c:set var="totalAmount" value="0"/>
<c:forEach var="entry" items="${cart.entrySet()}">
    <c:set var="product" value="${entry.value}"/>
    <%--单个商品的总额--%>
    <c:set var="amount" value="${product.price * product.count}"/>
    <%--所有商品的总额--%>
    <c:set var="totalAmount" value="${totalAmount + amount}"/>
</c:forEach>
<div align="center">
    <h2>您应支付:¥${totalAmount}</h2>
    <form action="checkout.jsp" method="POST">
        <input type="submit" value="确认订单">
    </form>
</div>

</body>
</html>

(5)购物车页面(cart.jsp)

CSS


table {
    border-collapse: collapse;
}

table, th, td {
    border: 1px solid gainsboro;
}

.titleTest {
    color: lightpink;
}

td {
    width: 20%;
}

a {
   text-decoration: none;
}

HTML

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%--
  Created by IntelliJ IDEA.
  User: 86189
  Date: 2023/10/21
  购物车页面
--%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购物车</title>

</head>
<body>
<h1 align="center" class="titleTest">我的购物车</h1>
<c:if test="${cart!=null && cart.size()>0}">
    <table style="width: 1000px" align="center">
        <tr>
            <th>商品信息</th>
            <th>单价</th>
            <th>数量</th>
            <th>金额</th>
        </tr>
        <c:forEach var="entry" items="${cart.entrySet()}">
            <tr>
                <c:set var="product" value="${entry.value}"/>
                <%----------------------商品信息--------------------%>
                <td><img src="${request.contextPath}${product.imagePath}" width="60px" height="80px">${product.name}</td>
                <%----------------------单价--------------------%>
                <td align="center">¥:${product.price}</td>
                <%----------------------数量-/+--------------------%>
                <td align="center">
                    <button onclick="void(0)"><a href="
                <%=request.getContextPath()+"/shoppingCart?op=sub&id="%>${product.id}
               "/>-
                    </button>
                        ${product.count}
                    <button onclick="void(0)"><a href="
                <%=request.getContextPath()+"/shoppingCart?op=add&id="%>${product.id}
               "/>+
                    </button>
                </td>
                <%----------------------金额--------------------%>
                <td align="center">¥:${product.count*product.price}</td>

            </tr>

        </c:forEach>
    </table>
</c:if>

<br><br>
<div style="width: 90%" align="right">
    <a href="home.jsp">继续购物</a>
    <a href="checkout.jsp">去结算</a>

</div>
</body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1902734.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

STM32-PWR和WDG看门狗

本内容基于江协科技STM32视频学习之后整理而得。 文章目录 1. PWR1.1 PWR简介1.2 电源框图1.3 上电复位和掉电复位1.4 可编程电压监测器1.5 低功耗模式1.6 模式选择1.7 睡眠模式1.8 停止模式1.9 待机模式1.10 库函数 2. WDG看门狗2.1 WDG简介2.2 IWDG框图2.3 IWDG键寄存器2.4 …

如何搭建Ubuntu环境安装禅道

一、禅道安装部署的环境要求 禅道安装部署环境推荐使用 Linux Apache PHP7.0以上版本 MySQL5.5以上版本/MariaDB的组合。Nginx其次&#xff0c;不推荐IIS PHP组合。禅道需要使用PHP的这些扩展&#xff1a;pdo、pdo_mysql、json、filte、openssl、mbstring、zlib、curl、gd、…

Qt源码解析之QObject

省去大部分virtual和public方法后&#xff0c;Qobject主要剩下以下成员&#xff1a; //qobject.h class Q_CORE_EXPORT Qobject{Q_OBJECTQ_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged)Q_DECLARE_PRIVATE(QObject) public:Q_I…

数据埋点从入门到了解

想讲讲为什么有埋点&#xff0c;举个例子 目录 什么是埋点&#xff1f;用途小红书上 埋点的主要类型代码示例1. 代码埋点前端埋点后端埋点 (Node.js 示例) 2. 全埋点示例3. 可视化埋点示例 解释常见问题埋点管理系统结论 王五是一名数据分析师&#xff0c;负责分析公司产品的用…

非NI GPIB卡与LabVIEW兼容性分析

在许多测试和测量应用中&#xff0c;通用接口总线&#xff08;GPIB&#xff09;是一种广泛使用的标准。尽管国家仪器公司&#xff08;NI&#xff09;提供的GPIB硬件和LabVIEW软件的组合被广泛接受和使用&#xff0c;但成本可能较高。因此&#xff0c;一些用户会考虑使用其他厂商…

什么是T0策略?有没有可以持仓自动做T的策略软件?

​​行情低迷&#xff0c;持仓被套&#xff0c;不想被动等待&#xff1f;长期持股&#xff0c;想要增厚持仓收益&#xff1f;有没有可以自动做T的工具或者策略&#xff1f;日内T0交易&#xff0c;做到降低持仓成本&#xff0c;优化收益预期。 什么是T0策略&#xff1f; 可以提…

Android最近任务显示的图片

Android最近任务显示的图片 1、TaskSnapshot截图1.1 snapshotTask1.2 drawAppThemeSnapshot 2、导航栏显示问题3、Recentan按键进入最近任务 1、TaskSnapshot截图 frameworks/base/services/core/java/com/android/server/wm/TaskSnapshotController.java frameworks/base/cor…

c++ primer plus 第15章友,异常和其他: 15.2.1 嵌套类和访问权限系

c primer plus 第15章友&#xff0c;异常和其他&#xff1a; 15.2.1 嵌套类和访问权限系 提示&#xff1a;这里可以添加系列文章的所有文章的目录&#xff0c;目录需要自己手动添加 例如&#xff1a;c primer plus 第15章友&#xff0c;异常和其他&#xff1a; 15.2.1 嵌套类和…

详解Amivest 流动性比率

详解Amivest 流动性比率 Claude-3.5-Sonnet Poe Amivest流动性比率是一个衡量证券市场流动性的重要指标。这个比率主要用于评估在不对价格造成重大影响的情况下,市场能够吸收多少交易量。以下是对Amivest流动性比率的详细解释: 定义: Amivest流动性比率是交易额与绝对收益率的…

柯桥职场英语学习商务英语口语生活英语培训生活口语学习

辣妹用英语怎么说&#xff1f; 辣妹在英语中通常被翻译为“hot girl”或“spicy girl”&#xff0c;但更常见和直接的是“hot chick”或简单地使用“hot”来形容。 举个例子: Shes a real hot girl with her trendy outfit and confident attitude. 她真是个辣妹&#xff0…

Linux:进程终止和进程替换

Linux&#xff1a;Linux&#xff1a;进程终止和进程替换 一、进程终止1.1 进程退出场景和创建退出方式 1.2 exit 和 _exit区别二、进程程序替换2.1 进程替换函数2.2 函数解释及命名解释函数解释命名解释 2.3 单进程程序替换&#xff08;无子进程&#xff09;2.3.1 带l函数进程替…

Ubuntu配置GitHub(第一次clone/push)

文章目录 1. 安装Git&检查连接2. 注册GitHub3. 生成&GitHub添加SSH3.1. 检查&删除已有id_rsa3.2. 生成SSH3.3. GitHub添加id_rsa.pub SSH3.4. 检查SSH 4. 继续开发可以参考参考 1. 安装Git&检查连接 安装 sudo apt-get install git检查SSH连接 ssh -T gitgi…

C++——stack和queue类用法指南

一、stack的介绍和使用 1.1 stack的介绍 1、stack是一种容器适配器&#xff0c;专门用在具有后进先出操作的上下文环境中&#xff0c;其删除只能从容器的一端进行插入与提取操作 2、stack是作为容器适配器被实现的&#xff0c;容器适配器即是对特定类封装作为其底层的容器&am…

clickhouse高可用可拓展部署

clickhouse高可用&可拓展部署 1.部署架构 1.1高可用架构 1.2硬件资源 部署服务 节点名称 节点ip 核数 内存 磁盘 zookeeper zk-01 / 4c 8G 100G zk-02 / 4c 8G 100G zk-03 / 4c 8G 100G clikehouse ck-01 / 32c 128G 2T ck-02 / 32c 128G 2T ck-03 / 32c 128G 2T ck-04 /…

设计模式之模版方法

模版方法介绍 模版方法&#xff08;Template Method&#xff09;模式是一种行为型设计模式&#xff0c;它定义了一个操作&#xff08;模板方法&#xff09;的基本组合与控制流程&#xff0c;将一些步骤&#xff08;抽象方法&#xff09;推迟到子类中&#xff0c;使得子类可以在…

LeetCode热题100刷题8:54. 螺旋矩阵、73. 矩阵置零、48. 旋转图像

54. 螺旋矩阵 class Solution { public:vector<int> spiralOrder(vector<vector<int>>& matrix) {vector<int> vec;if(matrix.empty())return vec;int left0;int right matrix[0].size()-1;int up0;int down matrix.size()-1;while(true) {for(i…

【TB作品】脉搏测量,ATMEGA8单片机,Proteus仿真,ATmega8控制脉搏测量与显示系统

硬件组成&#xff1a; LCD1602脉搏测量电路&#xff08;带灯&#xff09;蜂鸣器报警按键设置AT24C02 功能&#xff1a; &#xff08;1&#xff09;LCD1602主页显示脉搏、报警上限、报警下限&#xff1b; &#xff08;2&#xff09;五个按键&#xff1a;按键1&#xff1a;切换设…

axios的使用,处理请求和响应,axios拦截器

1、axios官网 https://www.axios-http.cn/docs/interceptors 2、安装 npm install axios 3、在onMouunted钩子函数中使用axios来发送请求&#xff0c;接受响应 4.出现的问题&#xff1a; &#xff08;1&#xff09; 但是如果发送请求请求时间过长&#xff0c;回出现请求待处…

RK3568 GPU介绍及使用

一、RK3568简介 RK3568四核64位Cortex-A55 处理器&#xff0c;采用全新ARM v8.2-A架构&#xff0c;主频最高可达2.0GHz&#xff0c;效能有大幅提升&#xff1b;采用22nm先进工艺&#xff0c;具有低功耗高性能的特点RK3568集成了双核心架构 GPU&#xff0c;高性能VPU以及高效能…

YOLOv8_obb数据集可视化[旋转目标检测实践篇]

先贴代码,周末再补充解析。 这个篇章主要是对标注好的标签进行可视化,虽然比较简单,但是可以从可视化代码中学习到YOLOv8是如何对标签进行解析的。 import cv2 import numpy as np import os import randomdef read_obb_labels(label_file_path):with open(label_file_path,…