计算机课程设计之蛋糕商城系统代码-基于javaweb的蛋糕商城系统-基于jsp的甜品销售平台代码

10 篇文章 2 订阅

计算机课程设计之蛋糕商城系统代码-基于javaweb的蛋糕商城系统-基于jsp的甜品销售平台代码

注意:该项目只展示部分功能,如需了解,评论区咨询即可。

1.开发环境

  • 开发语言:Java
  • 技术:Servlet+JSP+HTML+CSS+JavaScript+Bootstrap+jQuery
  • 数据库:MySQL
  • 架构:B/S
  • 源码类型: Web
  • 编译工具:Idea、Eclipse、MyEclipse (选其一)
  • 其他:jdk1.8、Tomcat8.0 、Navicat

2.系统的设计与实现

2.1 用户类型

用户角色分为 管理员、用户 这两类用户。

2.2 各角色功能模块

2.2.1 管理员

  • 登录;
  • 用户管理;
  • 商品类目管理;
  • 商品管理;
  • 节日管理;
  • 订单管理;
  • 发货。

2.2.2 用户

  • 注册;
  • 登录;
  • 修改密码;
  • 输入收货信息;
  • 搜索;
  • 查看热销商品;
  • 查看新品;
  • 加入购物车;
  • 提交订单;
  • 收货。

2.3 部分功能模块展示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

源码项目、定制开发、代码讲解、答辩辅导
希望和大家多多交流!!

  • 6
    点赞
  • 44
    收藏
    觉得还不错? 一键收藏
  • 49
    评论
搭建一个基于Javaweb蛋糕商城需要以下步骤: 1. 确定需求 首先需要明确商城的功能需求,例如商品展示、购物车、订单管理、支付等等。 2. 设计数据库 根据需求设计数据库,并创建相应的表。常见的表包括商品表、用户表、订单表等。 3. 搭建环境 搭建Java Web环境,例如Tomcat、MySQL等。 4. 编写代码 根据需求编写代码,包括前端页面、后端逻辑等。 以下是一个简单的代码示例: (1)创建商品表 ```mysql CREATE TABLE `goods` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) DEFAULT NULL, `price` decimal(10,2) DEFAULT NULL, `description` varchar(255) DEFAULT NULL, `image` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ``` (2)创建用户表 ```mysql CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ``` (3)创建订单表 ```mysql CREATE TABLE `order` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) DEFAULT NULL, `goods_id` int(11) DEFAULT NULL, `quantity` int(11) DEFAULT NULL, `total_price` decimal(10,2) DEFAULT NULL, `created_time` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ``` (4)编写商品展示页面 ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>商品列表</title> </head> <body> <h1>商品列表</h1> <table border="1"> <thead> <tr> <th>ID</th> <th>名称</th> <th>价格</th> <th>描述</th> <th>图片</th> </tr> </thead> <tbody> <% Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "password"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM goods"); while (rs.next()) { %> <tr> <td><%=rs.getInt("id")%></td> <td><%=rs.getString("name")%></td> <td><%=rs.getBigDecimal("price")%></td> <td><%=rs.getString("description")%></td> <td><img src="<%=rs.getString("image")%>" width="100" height="100"></td> </tr> <% } rs.close(); stmt.close(); conn.close(); %> </tbody> </table> </body> </html> ``` (5)编写用户登录页面 ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>用户登录</title> </head> <body> <h1>用户登录</h1> <form action="login" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username"><br> <label for="password">密码:</label> <input type="password" id="password" name="password"><br> <input type="submit" value="登录"> </form> </body> </html> ``` (6)编写用户登录逻辑 ```java public class LoginServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "password"); PreparedStatement stmt = conn.prepareStatement("SELECT * FROM user WHERE username=? AND password=?"); stmt.setString(1, username); stmt.setString(2, password); ResultSet rs = stmt.executeQuery(); if (rs.next()) { request.getSession().setAttribute("user_id", rs.getInt("id")); response.sendRedirect("goods"); } else { response.sendRedirect("login"); } rs.close(); stmt.close(); conn.close(); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); response.sendRedirect("login"); } } } ``` (7)编写购物车页面 ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>购物车</title> </head> <body> <h1>购物车</h1> <table border="1"> <thead> <tr> <th>ID</th> <th>名称</th> <th>单价</th> <th>数量</th> <th>小计</th> </tr> </thead> <tbody> <% int user_id = (int) request.getSession().getAttribute("user_id"); BigDecimal total_price = BigDecimal.ZERO; if (user_id != 0) { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "password"); PreparedStatement stmt = conn.prepareStatement("SELECT * FROM `order` WHERE user_id=?"); stmt.setInt(1, user_id); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PreparedStatement stmt2 = conn.prepareStatement("SELECT * FROM goods WHERE id=?"); stmt2.setInt(1, rs.getInt("goods_id")); ResultSet rs2 = stmt2.executeQuery(); if (rs2.next()) { %> <tr> <td><%=rs.getInt("id")%></td> <td><%=rs2.getString("name")%></td> <td><%=rs2.getBigDecimal("price")%></td> <td><%=rs.getInt("quantity")%></td> <td><%=rs.getBigDecimal("total_price")%></td> </tr> <% total_price = total_price.add(rs.getBigDecimal("total_price")); } rs2.close(); stmt2.close(); } rs.close(); stmt.close(); conn.close(); } %> </tbody> <tfoot> <tr> <td colspan="4">总价:</td> <td><%=total_price%></td> </tr> </tfoot> </table> </body> </html> ``` (8)编写添加商品到购物车逻辑 ```java public class AddToCartServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int user_id = (int) request.getSession().getAttribute("user_id"); int goods_id = Integer.parseInt(request.getParameter("goods_id")); int quantity = Integer.parseInt(request.getParameter("quantity")); try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "password"); PreparedStatement stmt = conn.prepareStatement("SELECT * FROM goods WHERE id=?"); stmt.setInt(1, goods_id); ResultSet rs = stmt.executeQuery(); if (rs.next()) { BigDecimal total_price = rs.getBigDecimal("price").multiply(new BigDecimal(quantity)); PreparedStatement stmt2 = conn.prepareStatement("INSERT INTO `order` (user_id, goods_id, quantity, total_price, created_time) VALUES (?, ?, ?, ?, NOW())"); stmt2.setInt(1, user_id); stmt2.setInt(2, goods_id); stmt2.setInt(3, quantity); stmt2.setBigDecimal(4, total_price); stmt2.executeUpdate(); stmt2.close(); } rs.close(); stmt.close(); conn.close(); response.sendRedirect("cart"); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); response.sendRedirect("goods"); } } } ``` 以上是一个简单的示例,实际项目中还需要考虑安全性、性能优化等因素。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 49
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值