├── web ├── images │ ├── 01.jpg │ ├── 02.jpg │ ├── 03.jpg │ ├── 04.jpg │ ├── 05.jpg │ ├── bg.bmp │ ├── cart.gif │ ├── dl.gif │ ├── hot.gif │ ├── logo.gif │ ├── none.jpg │ ├── test.gif │ ├── banner.bmp │ ├── account.gif │ ├── cartnext.gif │ ├── cartpre.gif │ ├── untitled.bmp │ ├── cartnavi-1.gif │ ├── cartnavi-2.gif │ └── cartnavi-3.gif ├── WEB-INF │ ├── classes │ │ └── com │ │ │ └── elephant │ │ │ ├── model │ │ │ ├── a.class │ │ │ ├── ConnDB.class │ │ │ ├── GoodsBean.class │ │ │ ├── MyCartBO.class │ │ │ ├── OrderBean.class │ │ │ ├── UserBean.class │ │ │ ├── GoodsBeanBO.class │ │ │ ├── OrderBeanCL.class │ │ │ ├── UserBeanCL.class │ │ │ ├── OrderUserBean.class │ │ │ └── OrderDetailBean.class │ │ │ └── controller │ │ │ ├── OrderCLServlet.class │ │ │ ├── ShoppingCL2Servlet.class │ │ │ ├── ShoppingCLServlet.class │ │ │ ├── ShowDetailsServlet.class │ │ │ └── UserManageServlet.class │ └── web.xml ├── css │ └── my.css ├── js │ └── banner.js ├── tail.jsp ├── failed.jsp ├── sucess.jsp ├── index.jsp ├── head.jsp ├── left.jsp ├── shopping4.jsp ├── login.jsp ├── right.jsp ├── signup.jsp ├── showDetail.jsp ├── showMyCart.jsp └── shopping3.jsp ├── README.md ├── src └── com │ └── elephant │ ├── model │ ├── ConnDB.java │ ├── OrderDetailBean.java │ ├── OrderBean.java │ ├── GoodsBean.java │ ├── UserBean.java │ ├── OrderUserBean.java │ ├── OrderBeanCL.java │ ├── MyCartBO.java │ ├── GoodsBeanBO.java │ └── UserBeanCL.java │ └── controller │ ├── ShoppingCL2Servlet.java │ ├── OrderCLServlet.java │ ├── ShowDetailsServlet.java │ ├── UserManageServlet.java │ └── ShoppingCLServlet.java └── Shoppings.sql /web/images/01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/01.jpg -------------------------------------------------------------------------------- /web/images/02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/02.jpg -------------------------------------------------------------------------------- /web/images/03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/03.jpg -------------------------------------------------------------------------------- /web/images/04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/04.jpg -------------------------------------------------------------------------------- /web/images/05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/05.jpg -------------------------------------------------------------------------------- /web/images/bg.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/bg.bmp -------------------------------------------------------------------------------- /web/images/cart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/cart.gif -------------------------------------------------------------------------------- /web/images/dl.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/dl.gif -------------------------------------------------------------------------------- /web/images/hot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/hot.gif -------------------------------------------------------------------------------- /web/images/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/logo.gif -------------------------------------------------------------------------------- /web/images/none.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/none.jpg -------------------------------------------------------------------------------- /web/images/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/test.gif -------------------------------------------------------------------------------- /web/images/banner.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/banner.bmp -------------------------------------------------------------------------------- /web/images/account.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/account.gif -------------------------------------------------------------------------------- /web/images/cartnext.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/cartnext.gif -------------------------------------------------------------------------------- /web/images/cartpre.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/cartpre.gif -------------------------------------------------------------------------------- /web/images/untitled.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/untitled.bmp -------------------------------------------------------------------------------- /web/images/cartnavi-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/cartnavi-1.gif -------------------------------------------------------------------------------- /web/images/cartnavi-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/cartnavi-2.gif -------------------------------------------------------------------------------- /web/images/cartnavi-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/images/cartnavi-3.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoShopping 2 | JSP+Java+Servlet,采用MVC模式开发的购物网站 3 | 主要模块: 4 | 5 | * 用户模块 6 | * 商品模块 7 | * 订单模块 8 | * JavaMail 9 | -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/a.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/a.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/ConnDB.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/ConnDB.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/GoodsBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/GoodsBean.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/MyCartBO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/MyCartBO.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/OrderBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/OrderBean.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/UserBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/UserBean.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/GoodsBeanBO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/GoodsBeanBO.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/OrderBeanCL.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/OrderBeanCL.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/UserBeanCL.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/UserBeanCL.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/OrderUserBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/OrderUserBean.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/model/OrderDetailBean.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/model/OrderDetailBean.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/controller/OrderCLServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/controller/OrderCLServlet.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/controller/ShoppingCL2Servlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/controller/ShoppingCL2Servlet.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/controller/ShoppingCLServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/controller/ShoppingCLServlet.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/controller/ShowDetailsServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/controller/ShowDetailsServlet.class -------------------------------------------------------------------------------- /web/WEB-INF/classes/com/elephant/controller/UserManageServlet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/newbeess/GoShopping/HEAD/web/WEB-INF/classes/com/elephant/controller/UserManageServlet.class -------------------------------------------------------------------------------- /web/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /web/css/my.css: -------------------------------------------------------------------------------- 1 | .abc { 2 | font-family: Georgia; 3 | font-size: 9pt; 4 | } 5 | .navi { 6 | font-family: Georgia; 7 | font-size: 9pt; 8 | background-color: #66CC33; 9 | } 10 | .mySlides { 11 | display:none; 12 | width: 170px; 13 | height: 170px; 14 | } 15 | . mytd{ 16 | border-collapse: collapse; 17 | padding: 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/com/elephant/model/ConnDB.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | 6 | /** 7 | * 获得数据库 链接 8 | *

9 | * Created by elephant on 16/7/8. 10 | */ 11 | public class ConnDB { 12 | private Connection con = null; 13 | 14 | public Connection getCon() { 15 | try { 16 | Class.forName("com.mysql.jdbc.Driver"); 17 | con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Shoppings?characterEncoding=UTF8", "root", "root"); 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | } 21 | return con; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /web/js/banner.js: -------------------------------------------------------------------------------- 1 | var slideIndex = 0; 2 | // 页面加载完成后,再执行JS函数 3 | window.onload = function () { 4 | carousel(); 5 | } 6 | function carousel() { 7 | // 获取 待滚动的图片 8 | var x = document.getElementsByClassName("mySlides"); 9 | // 将所有图片设置为不显示 10 | for (var i = 0; i < x.length; i++) { 11 | x[i].style.display = "none"; 12 | } 13 | // 检查范围 14 | if (slideIndex >= x.length) { 15 | slideIndex = 0; 16 | } 17 | // 显示图片 18 | x[slideIndex].style.display = "block"; 19 | slideIndex++; 20 | setTimeout(carousel, 2000); // Change image every 2 seconds 21 | } -------------------------------------------------------------------------------- /src/com/elephant/model/OrderDetailBean.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | /** 4 | * Created by elephant on 16/7/12. 5 | */ 6 | public class OrderDetailBean { 7 | private long ordersId; 8 | private long goodsId; 9 | private int nums; 10 | 11 | public int getNums() { 12 | return nums; 13 | } 14 | 15 | public void setNums(int nums) { 16 | this.nums = nums; 17 | } 18 | 19 | public long getOrdersId() { 20 | return ordersId; 21 | } 22 | 23 | public void setOrdersId(long ordersId) { 24 | this.ordersId = ordersId; 25 | } 26 | 27 | public long getGoodsId() { 28 | return goodsId; 29 | } 30 | 31 | public void setGoodsId(long goodsId) { 32 | this.goodsId = goodsId; 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /web/tail.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/8 5 | Time: 下午3:47 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
地址:北京市崇文区 客户服务热线直拨:010-0000000
邮编:100000 客服信箱:shawn@sina.com
Copyright 淘宝网
28 | -------------------------------------------------------------------------------- /web/failed.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/11 5 | Time: 下午8:41 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 操作失败 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 23 | 24 | 25 | 26 | 32 | 33 | 34 | 35 | 36 | 39 | 40 |
20 | 21 | 22 |
27 | 28 | 很遗憾,操作失败!!
29 | 返回登陆 30 | 31 |
37 | 38 |
41 | 42 | 43 | -------------------------------------------------------------------------------- /web/sucess.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/11 5 | Time: 下午8:41 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 操作成功 12 | 13 | 14 | 15 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 28 | 29 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 44 | 45 |
25 | 26 | 27 |
32 | 恭喜,操作成功!!
33 | 返回登陆 34 | 35 |
42 | 43 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /web/index.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/8 5 | Time: 上午11:46 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 22 | 23 | 24 | 25 | 28 | 31 | 32 | 33 | 34 | 37 | 38 |
19 | 20 | 21 |
26 | 27 | 29 | 30 |
35 | 36 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/com/elephant/model/OrderBean.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | /** 4 | * 和 Order表对应 5 | * Created by elephant on 16/7/12. 6 | */ 7 | public class OrderBean { 8 | private long orderId; 9 | private long userId; 10 | 11 | private String orderDate; 12 | private String payMode; 13 | private String isPayed; 14 | private float totalPrice; 15 | 16 | public String getOrderDate() { 17 | return orderDate; 18 | } 19 | 20 | public void setOrderDate(String orderDate) { 21 | this.orderDate = orderDate; 22 | } 23 | 24 | public long getOrderId() { 25 | return orderId; 26 | } 27 | 28 | public void setOrderId(long orderId) { 29 | this.orderId = orderId; 30 | } 31 | 32 | public long getUserId() { 33 | return userId; 34 | } 35 | 36 | public void setUserId(long userId) { 37 | this.userId = userId; 38 | } 39 | 40 | public String getPayMode() { 41 | return payMode; 42 | } 43 | 44 | public void setPayMode(String payMode) { 45 | this.payMode = payMode; 46 | } 47 | 48 | public String getIsPayed() { 49 | return isPayed; 50 | } 51 | 52 | public void setIsPayed(String isPayed) { 53 | this.isPayed = isPayed; 54 | } 55 | 56 | public float getTotalPrice() { 57 | return totalPrice; 58 | } 59 | 60 | public void setTotalPrice(float totalPrice) { 61 | this.totalPrice = totalPrice; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /web/head.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/8 5 | Time: 下午3:47 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 41 | 42 |

【我的账号】

19 |

【我的购物车】

28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
43 | -------------------------------------------------------------------------------- /src/com/elephant/controller/ShoppingCL2Servlet.java: -------------------------------------------------------------------------------- 1 | package com.elephant.controller; 2 | 3 | import com.elephant.model.UserBean; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.annotation.WebServlet; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import javax.servlet.http.HttpSession; 11 | import java.io.IOException; 12 | import java.io.PrintWriter; 13 | 14 | /** 15 | * Created by elephant on 16/7/12. 16 | */ 17 | @WebServlet(name = "shoppingcl2servlet", urlPatterns = "/shoppingcl2servlet") 18 | public class ShoppingCL2Servlet extends HttpServlet { 19 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 20 | response.setContentType("text/html"); 21 | response.setCharacterEncoding("utf-8"); 22 | PrintWriter pw = response.getWriter(); 23 | try { 24 | UserBean ub = (UserBean) request.getSession().getAttribute("userInfo"); 25 | if (ub == null) { 26 | // 用户没有登陆过 27 | request.getRequestDispatcher("login.jsp").forward(request, response); 28 | } else { 29 | // 用户登录过 30 | request.getRequestDispatcher("shopping3.jsp").forward(request, response); 31 | } 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | 37 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 38 | try { 39 | this.doPost(request, response); 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/elephant/model/GoodsBean.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | /** 4 | * 和Goods表做一个一一映射 5 | *

6 | * Created by elephant on 16/7/8. 7 | */ 8 | public class GoodsBean { 9 | 10 | private long goodsId; 11 | private String goodsName; 12 | private String goodsIntro; 13 | private float goodsPrice; 14 | private int goodsNum; 15 | private String publisher; 16 | private String photo; 17 | private String type; 18 | 19 | public long getGoodsId() { 20 | return goodsId; 21 | } 22 | 23 | public void setGoodsId(long goodsId) { 24 | this.goodsId = goodsId; 25 | } 26 | 27 | public String getGoodsName() { 28 | return goodsName; 29 | } 30 | 31 | public void setGoodsName(String goodsName) { 32 | this.goodsName = goodsName; 33 | } 34 | 35 | public String getGoodsIntro() { 36 | return goodsIntro; 37 | } 38 | 39 | public void setGoodsIntro(String goodsIntro) { 40 | this.goodsIntro = goodsIntro; 41 | } 42 | 43 | public float getGoodsPrice() { 44 | return goodsPrice; 45 | } 46 | 47 | public void setGoodsPrice(float goodsPrice) { 48 | this.goodsPrice = goodsPrice; 49 | } 50 | 51 | public int getGoodsNum() { 52 | return goodsNum; 53 | } 54 | 55 | public void setGoodsNum(int goodsNum) { 56 | this.goodsNum = goodsNum; 57 | } 58 | 59 | public String getPublisher() { 60 | return publisher; 61 | } 62 | 63 | public void setPublisher(String publisher) { 64 | this.publisher = publisher; 65 | } 66 | 67 | public String getPhoto() { 68 | return photo; 69 | } 70 | 71 | public void setPhoto(String photo) { 72 | this.photo = photo; 73 | } 74 | 75 | public String getType() { 76 | return type; 77 | } 78 | 79 | public void setType(String type) { 80 | this.type = type; 81 | } 82 | 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/com/elephant/model/UserBean.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | /** 4 | * Created by elephant on 16/7/11. 5 | */ 6 | public class UserBean { 7 | private int userId; 8 | private String userName; 9 | private String realName; 10 | private String password; 11 | private String email; 12 | private String phone; 13 | private String address; 14 | private String posrcode; 15 | private int grade; 16 | 17 | public String getUserName() { 18 | return userName; 19 | } 20 | 21 | public void setUserName(String userName) { 22 | this.userName = userName; 23 | } 24 | 25 | public int getUserId() { 26 | return userId; 27 | } 28 | 29 | public void setUserId(int userId) { 30 | this.userId = userId; 31 | } 32 | 33 | public String getRealName() { 34 | return realName; 35 | } 36 | 37 | public void setRealName(String realName) { 38 | this.realName = realName; 39 | } 40 | 41 | public String getPassword() { 42 | return password; 43 | } 44 | 45 | public void setPassword(String password) { 46 | this.password = password; 47 | } 48 | 49 | public String getEmail() { 50 | return email; 51 | } 52 | 53 | public void setEmail(String email) { 54 | this.email = email; 55 | } 56 | 57 | public String getPhone() { 58 | return phone; 59 | } 60 | 61 | public void setPhone(String phone) { 62 | this.phone = phone; 63 | } 64 | 65 | public String getAddress() { 66 | return address; 67 | } 68 | 69 | public void setAddress(String address) { 70 | this.address = address; 71 | } 72 | 73 | public String getPosrcode() { 74 | return posrcode; 75 | } 76 | 77 | public void setPosrcode(String posrcode) { 78 | this.posrcode = posrcode; 79 | } 80 | 81 | public int getGrade() { 82 | return grade; 83 | } 84 | 85 | public void setGrade(int grade) { 86 | this.grade = grade; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/com/elephant/controller/OrderCLServlet.java: -------------------------------------------------------------------------------- 1 | package com.elephant.controller; 2 | 3 | import com.elephant.model.MyCartBO; 4 | import com.elephant.model.OrderBeanCL; 5 | import com.elephant.model.OrderUserBean; 6 | import com.elephant.model.UserBean; 7 | 8 | import javax.servlet.ServletException; 9 | import javax.servlet.annotation.WebServlet; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import java.io.IOException; 14 | import java.io.PrintWriter; 15 | 16 | /** 17 | * 把订单写入Order和OrderDetail两个表中 18 | *

19 | * Created by elephant on 16/7/12. 20 | */ 21 | @WebServlet(name = "orderclservlet", urlPatterns = "/orderclservlet") 22 | public class OrderCLServlet extends HttpServlet { 23 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 24 | response.setContentType("text/html"); 25 | response.setCharacterEncoding("utf-8"); 26 | PrintWriter pw = response.getWriter(); 27 | 28 | try { 29 | MyCartBO mcb = (MyCartBO) request.getSession().getAttribute("mycart"); 30 | String userId = ((UserBean) request.getSession().getAttribute("userInfo")).getUserId() + ""; 31 | OrderBeanCL obc = new OrderBeanCL(); 32 | OrderUserBean oub=obc.addOrder(mcb, userId); 33 | if (oub!=null) { 34 | // 添加成功 35 | request.setAttribute("orderDetail",oub); 36 | request.getRequestDispatcher("shopping4.jsp").forward(request, response); 37 | } else { 38 | request.getRequestDispatcher("shopping3.jsp").forward(request, response); 39 | 40 | } 41 | 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | 47 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 48 | try { 49 | this.doPost(request, response); 50 | } catch (Exception e) { 51 | e.printStackTrace(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/elephant/controller/ShowDetailsServlet.java: -------------------------------------------------------------------------------- 1 | package com.elephant.controller; 2 | 3 | import com.elephant.model.GoodsBean; 4 | import com.elephant.model.GoodsBeanBO; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | import java.util.ArrayList; 12 | 13 | /** 14 | * 控制器 C 15 | * 显示电影 详情页 16 | *

17 | * Created by elephant on 16/7/9. 18 | */ 19 | @WebServlet(name = "/showdetailservlet", urlPatterns = "/showdetailservlet") 20 | public class ShowDetailsServlet extends javax.servlet.http.HttpServlet { 21 | /** 22 | * 相应Post请求 23 | * 24 | * @param request 25 | * @param response 26 | * @throws ServletException 27 | * @throws IOException 28 | */ 29 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 30 | try { 31 | response.setContentType("text/html"); 32 | response.setCharacterEncoding("utf-8"); 33 | String type = request.getParameter("type"); 34 | // 处理展示细节请求 35 | if (type.equals("showdetail")) { 36 | String id = request.getParameter("id"); 37 | GoodsBeanBO gbb = new GoodsBeanBO(); 38 | GoodsBean gb = gbb.getGoodsBean(id); 39 | request.setAttribute("gb", gb); 40 | request.getRequestDispatcher("showDetail.jsp").forward(request, response); 41 | } 42 | // 处理分页请求 43 | if (type.equals("fenye")) { 44 | String pageNow=request.getParameter("pageNow"); 45 | request.setAttribute("pageNow",pageNow); 46 | request.getRequestDispatcher("index.jsp").forward(request,response); 47 | } 48 | 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | 54 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 55 | try { 56 | this.doPost(request, response); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /web/left.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/8 5 | Time: 下午3:47 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 12 | 13 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 83 | 84 |
14 | 15 | 16 | 17 | 18 | 19 | 26 | 27 |
20 | 21 | 22 | 23 | 24 | 25 |
28 |
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 |
排行商品名称 点击次数
1笑傲江湖10
2笑傲江湖9
3笑傲江湖8
4笑傲江湖7
5笑傲江湖6
6笑傲江湖5
7笑傲江湖4
82 |
85 | 86 | -------------------------------------------------------------------------------- /web/shopping4.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.elephant.model.OrderUserBean" %> 2 | <%-- 3 | Created by IntelliJ IDEA. 4 | User: elephant 5 | Date: 16/7/12 6 | Time: 下午9:34 7 | To change this template use File | Settings | File Templates. 8 | --%> 9 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 10 | 11 | 12 | 订单完成 13 | <% 14 | OrderUserBean oub=(OrderUserBean)request.getAttribute("orderDetail"); 15 | %> 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 75 | 76 | 77 | 80 | 81 |
21 | 22 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 48 | 51 | 54 | 57 | 60 | 62 | 65 | 68 | 69 | 70 | 71 | 72 | 73 |
图片
订单详细信息
订单号收货人收货地址邮编电话总价用户名电子邮件 
46 | <%=oub.getOrdersId()%> 47 | 49 | <%=oub.getRealName()%> 50 | 52 | <%=oub.getAddress()%> 53 | 55 | <%=oub.getPostcode()%> 56 | 58 | <%=oub.getPhone()%> 59 | ¥<%=oub.getTotalPrice()%> 61 | 63 | <%=oub.getUserName()%> 64 | 66 | <%=oub.getEmail()%> 67 | 查看详情
您的订单已经完成,服务器将在稍后时候向您的电子邮箱发送确认信息,并确认订单信息。
74 |
78 | 79 |
82 | 83 | 84 | -------------------------------------------------------------------------------- /src/com/elephant/controller/UserManageServlet.java: -------------------------------------------------------------------------------- 1 | package com.elephant.controller; 2 | 3 | import com.elephant.model.MyCartBO; 4 | import com.elephant.model.UserBeanCL; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.annotation.WebServlet; 8 | import javax.servlet.http.HttpServlet; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import javax.servlet.http.HttpSession; 12 | import java.io.IOException; 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by elephant on 16/7/11. 17 | */ 18 | @WebServlet(name = "usermanageservlet", urlPatterns = "/usermanageservlet") 19 | public class UserManageServlet extends HttpServlet { 20 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 21 | try { 22 | response.setContentType("text/html"); 23 | response.setCharacterEncoding("utf-8"); 24 | String type = request.getParameter("type"); 25 | UserBeanCL ubc = new UserBeanCL(); 26 | 27 | // 处理用户登陆 28 | if (type.equals("login")) { 29 | String name = request.getParameter("username"); 30 | String password = request.getParameter("password"); 31 | // 验证通过,跳转到index页面 32 | if (ubc.checkUser(name, password)) { 33 | // 1. session 34 | HttpSession session = request.getSession(); 35 | session.setAttribute("userInfo", ubc.getUBbyName(name)); 36 | session.setMaxInactiveInterval(300);// 设置session时间为5分钟 37 | // 2. 取出购物车的信息 38 | MyCartBO mcb=(MyCartBO)request.getSession().getAttribute("mycart"); 39 | ArrayList al=mcb.showMyCart(); 40 | request.setAttribute("mycartInfo",al); 41 | request.getRequestDispatcher("shopping3.jsp").forward(request,response); 42 | } 43 | else { 44 | // 验证不通过 45 | request.getRequestDispatcher("login.jsp").forward(request,response); 46 | 47 | } 48 | } 49 | // 处理用户注册 50 | if (type.equals("signup")) { 51 | String id = request.getParameter("id"); 52 | String name = request.getParameter("username"); 53 | String realname = request.getParameter("realname"); 54 | String password = request.getParameter("password"); 55 | String mail = request.getParameter("mail"); 56 | String phone = request.getParameter("phone"); 57 | String address = request.getParameter("address"); 58 | String postcode = request.getParameter("postcode"); 59 | // 注册成功 60 | if (ubc.userSignUp(id, name, realname, password, mail, address, phone, postcode)) { 61 | response.sendRedirect("sucess.jsp"); 62 | } else { 63 | response.sendRedirect("failed.jsp"); 64 | } 65 | } 66 | 67 | } catch (Exception e) { 68 | e.printStackTrace(); 69 | } 70 | } 71 | 72 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 73 | try { 74 | this.doPost(request, response); 75 | } catch (Exception e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/com/elephant/controller/ShoppingCLServlet.java: -------------------------------------------------------------------------------- 1 | package com.elephant.controller; 2 | 3 | import com.elephant.model.GoodsBean; 4 | import com.elephant.model.GoodsBeanBO; 5 | import com.elephant.model.MyCartBO; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.annotation.WebServlet; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | import java.io.PipedWriter; 14 | import java.io.PrintWriter; 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by elephant on 16/7/11. 19 | */ 20 | @WebServlet(name = "shoppingclservlet", urlPatterns = "/shoppingclservlet") 21 | public class ShoppingCLServlet extends HttpServlet { 22 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 23 | response.setContentType("text/html"); 24 | response.setCharacterEncoding("utf-8"); 25 | PrintWriter pw = response.getWriter(); 26 | try { 27 | String type = request.getParameter("type"); 28 | // 从 Session中取出购物车, 29 | MyCartBO mcb = (MyCartBO) request.getSession().getAttribute("mycart"); 30 | // 处理购买逻辑 31 | if (type.equals("buy")) { 32 | // 如果取不出来,创建购物车放进Session 33 | String goodsId = request.getParameter("goodsId"); 34 | if (mcb == null) { 35 | mcb = new MyCartBO(); 36 | request.getSession().setAttribute("mycart", mcb); 37 | } 38 | // 默认,每次购买一张 39 | mcb.addGoods(goodsId, "1"); 40 | } 41 | if (type.equals("delGoods")) { 42 | // 删除一本书 43 | String goodsId = request.getParameter("goodsId"); 44 | mcb.removeGoods(goodsId); 45 | } else if (type.equals("showDetail")) { 46 | // 处理查看逻辑 47 | String id = request.getParameter("id"); 48 | GoodsBeanBO gbb = new GoodsBeanBO(); 49 | GoodsBean gb = gbb.getGoodsBean(id); 50 | request.setAttribute("gb", gb); 51 | request.getRequestDispatcher("showDetail.jsp").forward(request, response); 52 | } else if (type.equals("show")) { 53 | // 右上角购物车链接 54 | } else if (type.equals("delAll")) { 55 | // 清空购物车 56 | mcb.clean(); 57 | } else if (type.equals("updateGoods")) { 58 | // 修改数量 59 | String[] goodsIds = request.getParameterValues("goodsId"); 60 | String[] newNums = request.getParameterValues("newNums"); 61 | for (int i = 0; i < goodsIds.length; i++) { 62 | mcb.upGoods(goodsIds[i], newNums[i]); 63 | } 64 | 65 | 66 | } 67 | // 取出数据 68 | ArrayList al = mcb.showMyCart(); 69 | // 传递数据到显示页面 70 | request.setAttribute("mycart", al); 71 | // 跳转到页面显示 72 | request.getRequestDispatcher("showMyCart.jsp").forward(request, response); 73 | 74 | 75 | } catch (Exception e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | 80 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 81 | try { 82 | this.doPost(request, response); 83 | } catch (Exception e) { 84 | e.printStackTrace(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/com/elephant/model/OrderUserBean.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * 混合order和user两个Bean 7 | *

8 | *

9 | * Created by elephant on 16/7/13. 10 | */ 11 | public class OrderUserBean { 12 | // user 13 | private int userId; 14 | private String userName; 15 | private String realName; 16 | private String password; 17 | private String email; 18 | private String phone; 19 | 20 | 21 | private String address; 22 | private String postcode; 23 | private int grade; 24 | // order 25 | private int ordersId; 26 | private Date orderDate; 27 | private String payMode; 28 | private String isPayed; 29 | private float totalPrice; 30 | 31 | public String getAddress() { 32 | return address; 33 | } 34 | 35 | public void setAddress(String address) { 36 | this.address = address; 37 | } 38 | 39 | public Date getOrderDate() { 40 | return orderDate; 41 | } 42 | 43 | public void setOrderDate(Date orderDate) { 44 | this.orderDate = orderDate; 45 | } 46 | 47 | public int getUserId() { 48 | return userId; 49 | } 50 | 51 | public void setUserId(int userId) { 52 | this.userId = userId; 53 | } 54 | 55 | public String getUserName() { 56 | return userName; 57 | } 58 | 59 | public void setUserName(String userName) { 60 | this.userName = userName; 61 | } 62 | 63 | public String getRealName() { 64 | return realName; 65 | } 66 | 67 | public void setRealName(String realName) { 68 | this.realName = realName; 69 | } 70 | 71 | public String getPassword() { 72 | return password; 73 | } 74 | 75 | public void setPassword(String password) { 76 | this.password = password; 77 | } 78 | 79 | public String getEmail() { 80 | return email; 81 | } 82 | 83 | public void setEmail(String email) { 84 | this.email = email; 85 | } 86 | 87 | public String getPhone() { 88 | return phone; 89 | } 90 | 91 | public void setPhone(String phone) { 92 | this.phone = phone; 93 | } 94 | 95 | public String getPostcode() { 96 | return postcode; 97 | } 98 | 99 | public void setPostcode(String postcode) { 100 | this.postcode = postcode; 101 | } 102 | 103 | public int getGrade() { 104 | return grade; 105 | } 106 | 107 | public void setGrade(int grade) { 108 | this.grade = grade; 109 | } 110 | 111 | public int getOrdersId() { 112 | return ordersId; 113 | } 114 | 115 | public void setOrdersId(int ordersId) { 116 | this.ordersId = ordersId; 117 | } 118 | 119 | public String getPayMode() { 120 | return payMode; 121 | } 122 | 123 | public void setPayMode(String payMode) { 124 | this.payMode = payMode; 125 | } 126 | 127 | public String getIsPayed() { 128 | return isPayed; 129 | } 130 | 131 | public void setIsPayed(String isPayed) { 132 | this.isPayed = isPayed; 133 | } 134 | 135 | public float getTotalPrice() { 136 | return totalPrice; 137 | } 138 | 139 | public void setTotalPrice(float totalPrice) { 140 | this.totalPrice = totalPrice; 141 | } 142 | 143 | 144 | } 145 | -------------------------------------------------------------------------------- /web/login.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/11 5 | Time: 下午7:36 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 用户登陆 12 | 13 | 14 | <%-- 15 | Created by IntelliJ IDEA. 16 | User: elephant 17 | Date: 16/7/8 18 | Time: 上午11:46 19 | To change this template use File | Settings | File Templates. 20 | --%> 21 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 70 | 71 | 72 | 75 | 76 |
31 | 32 |
36 | 37 | 38 | 39 | 40 | 41 | 64 | 65 | 66 | 67 | 68 |
42 |
43 | 45 | 46 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 |
47 |
用户名:
密  码:
62 |
63 |
69 |
73 | 74 |
77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/com/elephant/model/OrderBeanCL.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.sql.Statement; 7 | import java.util.ArrayList; 8 | 9 | /** 10 | * 处理Order和OrderDetail表 11 | *

12 | *

13 | * Created by elephant on 16/7/12. 14 | */ 15 | public class OrderBeanCL { 16 | private Connection con = null; 17 | private PreparedStatement ps = null; 18 | private ResultSet rs = null; 19 | 20 | /** 21 | * 添加订单 22 | * 写入 orders表 23 | * 写入 ordersDetail表 24 | * 25 | * @param mcb 26 | * @param userId 27 | * @return 28 | */ 29 | public OrderUserBean addOrder(MyCartBO mcb, String userId) { 30 | OrderUserBean oub = new OrderUserBean(); 31 | boolean flag = true; 32 | try { 33 | con = new ConnDB().getCon(); 34 | ps = con.prepareStatement("INSERT INTO orders ( userId, isPayed, totalPrice) VALUES(?,?,?) "); 35 | ps.setInt(1, Integer.parseInt(userId)); 36 | ps.setString(2, "0"); 37 | ps.setFloat(3, mcb.getAllPrice()); 38 | int num = ps.executeUpdate(); 39 | if (num == 1) { 40 | // orders 插入成功 41 | // 从orders表中,取出刚刚插入的订单号 42 | ps = con.prepareStatement("SELECT max(orderId) FROM orders"); 43 | rs = ps.executeQuery(); 44 | int orderId = 0; 45 | if (rs.next()) { 46 | orderId = rs.getInt(1); 47 | } 48 | // 现在插入ordersDetail表 49 | // 从购物车中,取出购买的商品 50 | ArrayList al = mcb.showMyCart(); 51 | Statement sm = con.createStatement(); 52 | // 为了不影响效率,批量插入,而不是一个一个插入数据库 53 | for (int i = 0; i < al.size(); i++) { 54 | GoodsBean gb = (GoodsBean) al.get(i); 55 | String goodsId = gb.getGoodsId() + ""; 56 | String goodsNum = mcb.getNumById(goodsId); 57 | 58 | sm.addBatch("INSERT INTO orderDetail VALUES (" + orderId + "," + goodsId + "," + goodsNum + ")"); 59 | } 60 | // 批量执行任务 61 | sm.executeBatch(); 62 | ps = con.prepareStatement( 63 | "SELECT orderId,username,realname,address,postcode,phone,totalPrice,email FROM users,orders " + 64 | "WHERE orderId=? " + 65 | "AND users.userid=" + 66 | "(SELECT orders.userId FROM orders WHERE orderId= ? )"); 67 | ps.setLong(1, orderId); 68 | ps.setLong(2, orderId); 69 | 70 | rs = ps.executeQuery(); 71 | if (rs.next()) { 72 | // 封装到OrderUserBean中 73 | oub.setOrdersId(rs.getInt(1)); 74 | oub.setUserName(rs.getString(2)); 75 | oub.setRealName(rs.getString(3)); 76 | oub.setAddress(rs.getString(4)); 77 | oub.setPostcode(rs.getString(5)); 78 | oub.setPhone(rs.getString(6)); 79 | oub.setTotalPrice(rs.getFloat(7)); 80 | oub.setEmail(rs.getString(8)); 81 | } 82 | } 83 | } catch (Exception e) { 84 | flag = false; 85 | e.printStackTrace(); 86 | } finally { 87 | this.close(); 88 | } 89 | if (flag) { 90 | return oub; 91 | } else { 92 | return null; 93 | } 94 | } 95 | 96 | 97 | /** 98 | * 用来关闭数据库链接资源 99 | */ 100 | public void close() { 101 | try { 102 | if (rs != null) { 103 | rs.close(); 104 | rs = null; 105 | } 106 | if (ps != null) { 107 | ps.close(); 108 | ps = null; 109 | } 110 | if (con != null) { 111 | con.close(); 112 | con = null; 113 | } 114 | } catch (Exception e) { 115 | e.printStackTrace(); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/com/elephant/model/MyCartBO.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.Iterator; 9 | 10 | /** 11 | * 处理与购物相关的业务逻辑 12 | * Created by elephant on 16/7/11. 13 | */ 14 | public class MyCartBO { 15 | private Connection con = null; 16 | private PreparedStatement ps = null; 17 | private ResultSet rs = null; 18 | HashMap hm = new HashMap(); 19 | private float allPrice = 0.0f; 20 | 21 | public float getAllPrice() { 22 | return this.allPrice; 23 | } 24 | 25 | /** 26 | * 添加货物 27 | * 28 | * @param goodsId 29 | * @param goodsNum 30 | */ 31 | public void addGoods(String goodsId, String goodsNum) { 32 | hm.put(goodsId, goodsNum); 33 | } 34 | 35 | 36 | /** 37 | * 删除货物 38 | * 39 | * @param goodsId 40 | */ 41 | public void removeGoods(String goodsId) { 42 | hm.remove(goodsId); 43 | } 44 | 45 | /** 46 | * 晴空购物车 47 | */ 48 | public void clean() { 49 | hm.clear(); 50 | } 51 | 52 | /** 53 | * 修改数量 54 | * 55 | * @param goodsId 56 | * @param goodsNum 57 | */ 58 | public void upGoods(String goodsId, String goodsNum) { 59 | hm.put(goodsId, goodsNum); 60 | } 61 | 62 | /** 63 | * 显示购物车 64 | * 65 | * @return 66 | */ 67 | public ArrayList showMyCart() { 68 | ArrayList al = new ArrayList(); 69 | try { 70 | // 定义迭代器 71 | Iterator iterator = hm.keySet().iterator(); 72 | String sub = "("; 73 | while (iterator.hasNext()) { 74 | String goodsId = iterator.next(); 75 | // 判断goodId是否是最后一个 76 | if (iterator.hasNext()) { 77 | sub = sub + goodsId + ","; 78 | } else { 79 | sub = sub + goodsId; 80 | } 81 | } 82 | sub = sub + ")"; 83 | ConnDB connDB = new ConnDB(); 84 | con = connDB.getCon(); 85 | ps = con.prepareStatement("SELECT * FROM goods WHERE goodsId IN " + sub); 86 | rs = ps.executeQuery(); 87 | this.allPrice = 0.0f; 88 | while (rs.next()) { 89 | GoodsBean gb = new GoodsBean(); 90 | long id = rs.getLong(1); 91 | gb.setGoodsId(id); 92 | gb.setGoodsName(rs.getString(2)); 93 | gb.setGoodsIntro(rs.getString(3)); 94 | long price = rs.getLong(4); 95 | gb.setGoodsPrice(price); 96 | gb.setGoodsNum(rs.getInt(5)); 97 | gb.setPublisher(rs.getString(6)); 98 | gb.setPhoto(rs.getString(7)); 99 | gb.setType(rs.getString(8)); 100 | al.add(gb); 101 | this.allPrice = this.allPrice + price * Integer.parseInt(this.getNumById(id + "")); 102 | } 103 | } catch (Exception e) { 104 | e.printStackTrace(); 105 | } finally { 106 | this.close(); 107 | } 108 | return al; 109 | } 110 | 111 | /** 112 | * 通过ID号,返回商品数量 113 | * 114 | * @param id 115 | * @return 116 | */ 117 | public String getNumById(String id) { 118 | return hm.get(id); 119 | } 120 | 121 | /** 122 | * 用来关闭数据库链接资源 123 | */ 124 | public void close() { 125 | try { 126 | if (rs != null) { 127 | rs.close(); 128 | rs = null; 129 | } 130 | if (ps != null) { 131 | ps.close(); 132 | ps = null; 133 | } 134 | if (con != null) { 135 | con.close(); 136 | con = null; 137 | } 138 | } catch (Exception e) { 139 | e.printStackTrace(); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/com/elephant/model/GoodsBeanBO.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | import java.sql.*; 4 | import java.util.ArrayList; 5 | 6 | /** 7 | * 处理,和Goods表相关的业务逻辑 8 | *

9 | * Created by elephant on 16/7/8. 10 | */ 11 | public class GoodsBeanBO { 12 | private Connection con = null; 13 | private PreparedStatement ps = null; 14 | private ResultSet rs = null; 15 | 16 | /** 17 | * 通过 ID 获取 货物的详细信息(GoodsBean对象) 18 | * 19 | * @param id 20 | * @return 21 | */ 22 | public GoodsBean getGoodsBean(String id) { 23 | GoodsBean gb = new GoodsBean(); 24 | try { 25 | ConnDB connDB = new ConnDB(); 26 | con = connDB.getCon(); 27 | ps = con.prepareStatement("SELECT * FROM goods WHERE goodsId=?"); 28 | ps.setString(1, id); 29 | rs = ps.executeQuery(); 30 | if (rs.next()) { 31 | gb.setGoodsId(rs.getLong(1)); 32 | gb.setGoodsName(rs.getString(2)); 33 | gb.setGoodsIntro(rs.getString(3)); 34 | gb.setGoodsPrice(rs.getLong(4)); 35 | gb.setGoodsNum(rs.getInt(5)); 36 | gb.setPublisher(rs.getString(6)); 37 | gb.setPhoto(rs.getString(7)); 38 | gb.setType(rs.getString(8)); 39 | } 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } finally { 43 | this.close(); 44 | } 45 | return gb; 46 | } 47 | 48 | /** 49 | * 分页 50 | * 51 | * @param pageSize 52 | * @param pageNow 53 | * @return 54 | */ 55 | public ArrayList getGoodsByPage(int pageSize, int pageNow) { 56 | ArrayList al = new ArrayList(); 57 | try { 58 | ConnDB connDB = new ConnDB(); 59 | con = connDB.getCon(); 60 | ps = con.prepareStatement("SELECT * FROM goods LIMIT ?,?"); 61 | ps.setInt(1,(pageNow-1)*pageSize); 62 | ps.setInt(2,pageSize); 63 | rs = ps.executeQuery(); 64 | while (rs.next()) { 65 | GoodsBean gb = new GoodsBean(); 66 | gb.setGoodsId(rs.getInt(1)); 67 | gb.setGoodsName(rs.getString(2)); 68 | gb.setGoodsIntro(rs.getString(3)); 69 | gb.setGoodsPrice(rs.getLong(4)); 70 | gb.setGoodsNum(rs.getInt(5)); 71 | gb.setPublisher(rs.getString(6)); 72 | gb.setPhoto(rs.getString(7)); 73 | gb.setType(rs.getString(8)); 74 | al.add(gb); 75 | } 76 | } catch (Exception e) { 77 | e.printStackTrace(); 78 | } finally { 79 | this.close(); 80 | } 81 | return al; 82 | } 83 | 84 | /** 85 | * 获得分页页数 86 | * 87 | * @param pageSize 88 | * @return 89 | */ 90 | public int getPageCount(int pageSize) { 91 | int pageCount = 0, rowCount = 0; 92 | try { 93 | ConnDB connDB = new ConnDB(); 94 | con = connDB.getCon(); 95 | ps = con.prepareStatement("SELECT count(*) FROM goods"); 96 | rs = ps.executeQuery(); 97 | if (rs.next()) { 98 | rowCount = rs.getInt(1); 99 | } 100 | if (rowCount % pageSize == 0) { 101 | pageCount = rowCount / pageSize; 102 | } else { 103 | pageCount = rowCount / pageSize + 1; 104 | } 105 | } catch (Exception e) { 106 | 107 | } finally { 108 | this.close(); 109 | } 110 | return pageCount; 111 | } 112 | 113 | /** 114 | * 用来关闭数据库链接资源 115 | */ 116 | public void close() { 117 | try { 118 | if (rs != null) { 119 | rs.close(); 120 | rs = null; 121 | } 122 | if (ps != null) { 123 | ps.close(); 124 | ps = null; 125 | } 126 | if (con != null) { 127 | con.close(); 128 | con = null; 129 | } 130 | } catch (Exception e) { 131 | e.printStackTrace(); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /web/right.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.elephant.model.GoodsBeanBO" %> 2 | <%@ page import="java.util.ArrayList" %> 3 | <%@ page import="com.elephant.model.GoodsBean" %> 4 | <%-- 5 | Created by IntelliJ IDEA. 6 | User: elephant 7 | Date: 16/7/8 8 | Time: 下午3:47 9 | To change this template use File | Settings | File Templates. 10 | --%> 11 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 12 | <% 13 | int pageNow = 1; 14 | String pageNow_temp = (String) request.getAttribute("pageNow"); 15 | GoodsBeanBO gbbo = new GoodsBeanBO(); 16 | if (pageNow_temp != null) { 17 | pageNow = Integer.parseInt(pageNow_temp); 18 | } 19 | ArrayList al = gbbo.getGoodsByPage(6, pageNow); 20 | 21 | // 最后一页,若显示不全,用荷花图补充上 22 | if (al.size() < 6) { 23 | for (int m = al.size(); m < 6; m++) { 24 | GoodsBean gb = new GoodsBean(); 25 | gb = new GoodsBean(); 26 | gb.setGoodsId(0); 27 | gb.setGoodsName("荷花"); 28 | gb.setPhoto("none.jpg"); 29 | gb.setGoodsIntro("没有书了"); 30 | gb.setGoodsPrice(0.0f); 31 | al.add(m, gb); 32 | } 33 | } 34 | // 得到共有多少页 35 | int pageCount = gbbo.getPageCount(6); 36 | %> 37 | 38 | <%--right table第一行--%> 39 | 40 | 41 | 42 | <%--right table第二行--%> 43 | <% 44 | for (int i = 0; i < 2; i++) { 45 | 46 | %> 47 | 48 | <% 49 | //取出三个 50 | for (int j = 0; j < 3; j++) { 51 | GoodsBean gb = (GoodsBean) al.get(i * 3 + j); 52 | 53 | %> 54 | 75 | <% 76 | } 77 | %> 78 | 79 | 80 | 81 | <% 82 | } 83 | %> 84 | 85 | 86 | 87 | <%--right table第四行--%> 88 | 89 | 90 | 91 | 104 | 105 | 106 |
55 | 56 | 57 | 58 | 59 | 60 | 61 | 64 | 65 | 66 | 68 | 69 | 70 | 72 | 73 |
 
<%=gb.getGoodsName()%> 63 |
价格: <%=gb.getGoodsPrice()%> 67 |
简单介绍:<%=gb.getGoodsIntro()%> 71 |
74 |
92 | <% 93 | for (int k = 1; k <= pageCount; k++) { 94 | %> 95 | <%=k%> 96 | 97 |     98 | <% 99 | 100 | } 101 | %> 102 | 103 |
107 | -------------------------------------------------------------------------------- /src/com/elephant/model/UserBeanCL.java: -------------------------------------------------------------------------------- 1 | package com.elephant.model; 2 | 3 | import java.sql.Connection; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | 7 | /** 8 | * Created by elephant on 16/7/11. 9 | */ 10 | public class UserBeanCL { 11 | private Connection con = null; 12 | private PreparedStatement ps = null; 13 | private ResultSet rs = null; 14 | 15 | 16 | /** 17 | * 通过用户名,获得用户信息 18 | * 19 | * @param name 20 | * @return 21 | */ 22 | public UserBean getUBbyName(String name) { 23 | UserBean ub = new UserBean(); 24 | try { 25 | ConnDB connDB = new ConnDB(); 26 | con = connDB.getCon(); 27 | ps = con.prepareStatement("SELECT * FROM users WHERE username=?"); 28 | ps.setString(1, name); 29 | rs = ps.executeQuery(); 30 | if (rs.next()){ 31 | ub.setUserId(rs.getInt(1)); 32 | ub.setUserName(rs.getString(2)); 33 | ub.setRealName(rs.getString(3)); 34 | ub.setPassword(rs.getString(4)); 35 | ub.setEmail(rs.getString(5)); 36 | ub.setPhone(rs.getString(6)); 37 | ub.setAddress(rs.getString(7)); 38 | ub.setPosrcode(rs.getString(8)); 39 | ub.setGrade(rs.getInt(9)); 40 | } 41 | 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | } finally { 45 | this.close(); 46 | } 47 | return ub; 48 | } 49 | 50 | /** 51 | * 验证用户 52 | * 53 | * @param name 54 | * @param password 55 | * @return 56 | */ 57 | public boolean checkUser(String name, String password) { 58 | boolean flag = false; 59 | try { 60 | ConnDB connDB = new ConnDB(); 61 | con = connDB.getCon(); 62 | ps = con.prepareStatement("SELECT passwd FROM users WHERE username=?"); 63 | ps.setString(1, name); 64 | rs = ps.executeQuery(); 65 | if (rs.next()) { 66 | String passwordSQL = rs.getString(1); 67 | if (password.equals(passwordSQL)) { 68 | flag = true; 69 | } 70 | 71 | } 72 | } catch (Exception e) { 73 | e.printStackTrace(); 74 | } finally { 75 | this.close(); 76 | } 77 | return flag; 78 | } 79 | 80 | /** 81 | * 用户注册 82 | * 83 | * @param name 84 | * @param realname 85 | * @param password 86 | * @param mail 87 | * @param address 88 | * @param phone 89 | * @param postcode 90 | * @return 91 | */ 92 | public boolean userSignUp(String id, String name, String realname, String password, String mail, String address, String phone, String postcode) { 93 | boolean flag = false; 94 | try { 95 | ConnDB connDB = new ConnDB(); 96 | con = connDB.getCon(); 97 | ps = con.prepareStatement("INSERT INTO users (username, realname, passwd, email, phone, address, postcode,userid,grade) VALUES (?,?,?,?,?,?,?,?,?)"); 98 | ps.setString(1, name); 99 | ps.setString(2, realname); 100 | ps.setString(3, password); 101 | ps.setString(4, mail); 102 | ps.setString(5, phone); 103 | ps.setString(6, address); 104 | ps.setString(7, postcode); 105 | ps.setString(8, id); 106 | ps.setInt(9, 2); 107 | int num = ps.executeUpdate(); 108 | if (num == 1) { 109 | flag = true; 110 | } 111 | } catch (Exception e) { 112 | e.printStackTrace(); 113 | } finally { 114 | this.close(); 115 | } 116 | return flag; 117 | } 118 | 119 | /** 120 | * 用来关闭数据库链接资源 121 | */ 122 | public void close() { 123 | try { 124 | if (rs != null) { 125 | rs.close(); 126 | rs = null; 127 | } 128 | if (ps != null) { 129 | ps.close(); 130 | ps = null; 131 | } 132 | if (con != null) { 133 | con.close(); 134 | con = null; 135 | } 136 | } catch (Exception e) { 137 | e.printStackTrace(); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /web/signup.jsp: -------------------------------------------------------------------------------- 1 | <%-- 2 | Created by IntelliJ IDEA. 3 | User: elephant 4 | Date: 16/7/11 5 | Time: 下午8:17 6 | To change this template use File | Settings | File Templates. 7 | --%> 8 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 | 10 | 11 | 用户注册 12 | 13 | 14 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 28 | 29 | 30 | 31 |
25 | 26 | 27 |
32 | 33 | 34 | 35 | 37 | 38 | 39 | 42 | 43 | 44 | 47 | 48 | 49 | 52 | 53 | 54 | 57 | 58 | 59 | 62 | 63 | 64 | 67 | 68 | 69 | 72 | 73 | 74 | 77 | 78 | 79 | 82 | 83 | 84 | 87 | 88 | 89 |

用户注册

36 |
40 | ID: 41 |
45 | 用户名: 46 |
50 | 密码: 51 |
55 | 确认密码: 56 |
60 | 真实姓名: 61 |
65 | 邮箱: 66 |
70 | 手机号码: 71 |
75 | 联系地址: 76 |
80 | 邮编: 81 |
85 | 86 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /web/showDetail.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.elephant.model.GoodsBean" %> 2 | <%-- 3 | Created by IntelliJ IDEA. 4 | User: elephant 5 | Date: 16/7/8 6 | Time: 下午10:14 7 | To change this template use File | Settings | File Templates. 8 | --%> 9 | <%@ page contentType="text/html;charset=utf-8" language="java" %> 10 | <% 11 | // 取出要显示的信息 12 | GoodsBean gb = (GoodsBean) request.getAttribute("gb"); 13 | %> 14 | 15 | 16 | 17 | 18 | 电影详情 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 40 | 41 | 42 | 43 |

44 | 45 | 46 | 49 | 50 | 51 | 96 | 97 | 98 | 99 | 102 | 103 |
47 | 48 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | 61 | 62 | 64 | 65 | 66 | 67 | 68 | 69 | 71 | 72 | 73 | 75 | 76 | 77 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 90 | 91 | 92 | 93 | 94 |
 
<%=gb.getGoodsName()%> 59 |
价格:¥<%=gb.getGoodsPrice()%> 63 |
 
ISBN:<%=gb.getGoodsId()%> 70 |
类型:<%=gb.getType()%> 74 |
出版商<%=gb.getPublisher()%> 78 |
 
89 |
 
95 |
100 | 101 |
104 |
105 | 106 | 107 | -------------------------------------------------------------------------------- /web/showMyCart.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" import="java.util.*,com.elephant.model.*" pageEncoding="utf-8" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | My JSP 'showMycart.jsp' starting page 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 27 | <% 28 | MyCartBO mcb = (MyCartBO) request.getSession().getAttribute("mycart"); 29 | 30 | ArrayList al = (ArrayList) request.getAttribute("mycart"); 31 | %> 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 96 | 97 | 114 | 115 |
39 | 40 |
44 |
45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | <% 57 | for (int i = 0; i < al.size(); i++) { 58 | GoodsBean gb = (GoodsBean) al.get(i); 59 | %> 60 | 61 | 63 | 65 | 67 | 68 | 72 | 74 | 76 | 77 | 78 | <% 79 | } 80 | %> 81 | 82 | 83 | 84 | 85 | 87 | 88 | 89 | 90 | 91 | 92 | 93 |
48 |
编1号名称单价数量
<%=gb.getGoodsId()%> 62 | <%=gb.getGoodsName()%> 64 | <%=gb.getGoodsPrice()%> 66 | 69 | 70 | "/> 71 | 删除 73 | 查看 75 |
  86 |  
 
94 |
95 |
98 | 99 | 100 | 106 | 111 | 112 |
您共选择了价值¥<%=mcb.getAllPrice()%>的商品,点 101 | 102 | 此处 103 | 104 | 继续购物。 105 | 107 | 108 | 109 | 110 |
113 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /web/shopping3.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="com.elephant.model.UserBean" %> 2 | <%@ page import="java.util.ArrayList" %> 3 | <%@ page import="com.elephant.model.GoodsBean" %> 4 | <%@ page import="com.elephant.model.MyCartBO" %> 5 | <%-- 6 | Created by IntelliJ IDEA. 7 | User: elephant 8 | Date: 16/7/12 9 | Time: 下午3:56 10 | To change this template use File | Settings | File Templates. 11 | --%> 12 | <%@ page contentType="text/html;charset=UTF-8" language="java" %> 13 | 14 | 15 | 16 | <% 17 | UserBean ub = (UserBean) session.getAttribute("userInfo"); 18 | ArrayList al = (ArrayList) request.getAttribute("mycartInfo"); 19 | MyCartBO mcb = (MyCartBO) session.getAttribute("mycart"); 20 | %> 21 | 22 | 23 |
24 | 25 | 26 | 29 | 30 | 31 | 125 | 126 | 127 | 130 | 131 |
27 | 28 |
32 | 33 | 34 | 35 | 36 | 37 | 73 | 74 | 75 | 117 | 118 | 119 | 122 | 123 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 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 |
购买人的信息
用 户 名: 45 |
*真实姓名:
*家庭住址:
*联系电话:
*电子邮件:
*邮  编:
72 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | <% 87 | for (int i = 0; i < al.size(); i++) { 88 | GoodsBean gb = (GoodsBean) al.get(i); 89 | %> 90 | 91 | 92 | 95 | 98 | 101 | 104 | 105 | <% 106 | } 107 | %> 108 | 109 | 110 | 111 | 112 | 114 | 115 |
我的购物车情况
编号商品名称单价数量
93 | <%=gb.getGoodsId()%> 94 | 96 | <%=gb.getGoodsName()%> 97 | 99 | <%=gb.getGoodsPrice()%> 100 | 102 | <%=mcb.getNumById(gb.getGoodsId() + "")%> 103 |
您共选择了价值¥<%=mcb.getAllPrice()%>的商品。
116 |
120 | 121 |
124 |
128 | 129 |
132 |
133 | 134 | 135 | -------------------------------------------------------------------------------- /Shoppings.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.6.3 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Generation Time: Jul 14, 2016 at 06:31 AM 7 | -- Server version: 5.7.12 8 | -- PHP Version: 5.5.34 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8mb4 */; 18 | 19 | -- 20 | -- Database: `Shoppings` 21 | -- 22 | 23 | -- -------------------------------------------------------- 24 | 25 | -- 26 | -- Table structure for table `goods` 27 | -- 28 | 29 | CREATE TABLE `goods` ( 30 | `goodsId` int(11) NOT NULL, 31 | `goodsName` varchar(40) COLLATE utf8_unicode_ci NOT NULL, 32 | `goodsIntro` varchar(500) COLLATE utf8_unicode_ci NOT NULL, 33 | `goodsPrice` float NOT NULL, 34 | `goodsNum` int(11) NOT NULL, 35 | `publisher` varchar(40) COLLATE utf8_unicode_ci NOT NULL, 36 | `photo` varchar(40) COLLATE utf8_unicode_ci NOT NULL, 37 | `type` varchar(10) COLLATE utf8_unicode_ci NOT NULL 38 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 39 | 40 | -- 41 | -- Dumping data for table `goods` 42 | -- 43 | 44 | INSERT INTO `goods` (`goodsId`, `goodsName`, `goodsIntro`, `goodsPrice`, `goodsNum`, `publisher`, `photo`, `type`) VALUES 45 | (1, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 46 | (2, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 47 | (3, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 48 | (4, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 49 | (5, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'), 50 | (6, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 51 | (7, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 52 | (8, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 53 | (9, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 54 | (10, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'), 55 | (11, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 56 | (12, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 57 | (13, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 58 | (14, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 59 | (15, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'), 60 | (16, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 61 | (17, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 62 | (18, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 63 | (19, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 64 | (20, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'), 65 | (26, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 66 | (27, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 67 | (28, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 68 | (29, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 69 | (30, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'), 70 | (31, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 71 | (32, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 72 | (33, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 73 | (34, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 74 | (35, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'), 75 | (36, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 76 | (37, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 77 | (38, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 78 | (39, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 79 | (40, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'), 80 | (41, '黑白森林', '刘青云主要大片', 59, 1, '香港嘉禾出品', '01.jpg', '香港电影'), 81 | (42, '金鸡II', '刘青云主要大片', 45, 1, '香港嘉禾出品', '02.jpg', '香港电影'), 82 | (43, '靓女菜馆', '这是一部好片', 99, 1, '香港嘉禾出品', '03.jpg', '香港电影'), 83 | (44, '布衣神相', '这是一部好片', 33, 1, '香港嘉禾出品', '04.jpg', '香港电影'), 84 | (45, '洛神', '这是一部好片', 55, 1, '香港嘉禾出品', '05.jpg', '香港电影'); 85 | 86 | -- -------------------------------------------------------- 87 | 88 | -- 89 | -- Table structure for table `orderDetail` 90 | -- 91 | 92 | CREATE TABLE `orderDetail` ( 93 | `orderId` int(11) NOT NULL, 94 | `goodsId` int(11) NOT NULL, 95 | `nums` int(11) NOT NULL 96 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 97 | 98 | -- 99 | -- Dumping data for table `orderDetail` 100 | -- 101 | 102 | INSERT INTO `orderDetail` (`orderId`, `goodsId`, `nums`) VALUES 103 | (3, 1, 1); 104 | 105 | -- -------------------------------------------------------- 106 | 107 | -- 108 | -- Table structure for table `orders` 109 | -- 110 | 111 | CREATE TABLE `orders` ( 112 | `orderId` int(11) NOT NULL, 113 | `orderDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 114 | `payMode` enum('cash','zhifubao') COLLATE utf8_unicode_ci DEFAULT 'cash', 115 | `isPayed` enum('0','1') COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', 116 | `totalPrice` float DEFAULT NULL, 117 | `userId` int(11) NOT NULL 118 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 119 | 120 | -- 121 | -- Dumping data for table `orders` 122 | -- 123 | 124 | INSERT INTO `orders` (`orderId`, `orderDate`, `payMode`, `isPayed`, `totalPrice`, `userId`) VALUES 125 | (1, '2016-07-14 06:17:41', 'cash', '0', 99, 1), 126 | (2, '2016-07-14 06:20:12', 'cash', '0', 59, 1), 127 | (3, '2016-07-14 06:21:06', 'cash', '0', 59, 1); 128 | 129 | -- -------------------------------------------------------- 130 | 131 | -- 132 | -- Table structure for table `users` 133 | -- 134 | 135 | CREATE TABLE `users` ( 136 | `userid` int(11) NOT NULL, 137 | `username` varchar(30) COLLATE utf8_unicode_ci NOT NULL, 138 | `realname` varchar(30) COLLATE utf8_unicode_ci NOT NULL, 139 | `passwd` varchar(30) COLLATE utf8_unicode_ci NOT NULL, 140 | `email` varchar(40) COLLATE utf8_unicode_ci NOT NULL, 141 | `phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL, 142 | `address` varchar(30) COLLATE utf8_unicode_ci NOT NULL, 143 | `postcode` char(6) COLLATE utf8_unicode_ci NOT NULL, 144 | `grade` int(11) DEFAULT '5' 145 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 146 | 147 | -- 148 | -- Dumping data for table `users` 149 | -- 150 | 151 | INSERT INTO `users` (`userid`, `username`, `realname`, `passwd`, `email`, `phone`, `address`, `postcode`, `grade`) VALUES 152 | (1, 'admin', '周杰伦', 'admin', 'admin@tt.com', '131501288888', '北京市朝阳门街道朝阳群众', '123456', 1); 153 | 154 | -- 155 | -- Indexes for dumped tables 156 | -- 157 | 158 | -- 159 | -- Indexes for table `goods` 160 | -- 161 | ALTER TABLE `goods` 162 | ADD PRIMARY KEY (`goodsId`); 163 | 164 | -- 165 | -- Indexes for table `orderDetail` 166 | -- 167 | ALTER TABLE `orderDetail` 168 | ADD PRIMARY KEY (`orderId`), 169 | ADD KEY `ordersId` (`orderId`), 170 | ADD KEY `goodsId` (`goodsId`); 171 | 172 | -- 173 | -- Indexes for table `orders` 174 | -- 175 | ALTER TABLE `orders` 176 | ADD PRIMARY KEY (`orderId`), 177 | ADD KEY `userId` (`userId`); 178 | 179 | -- 180 | -- Indexes for table `users` 181 | -- 182 | ALTER TABLE `users` 183 | ADD PRIMARY KEY (`userid`), 184 | ADD UNIQUE KEY `username` (`username`); 185 | 186 | -- 187 | -- AUTO_INCREMENT for dumped tables 188 | -- 189 | 190 | -- 191 | -- AUTO_INCREMENT for table `orders` 192 | -- 193 | ALTER TABLE `orders` 194 | MODIFY `orderId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; 195 | -- 196 | -- AUTO_INCREMENT for table `users` 197 | -- 198 | ALTER TABLE `users` 199 | MODIFY `userid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; 200 | -- 201 | -- Constraints for dumped tables 202 | -- 203 | 204 | -- 205 | -- Constraints for table `orderDetail` 206 | -- 207 | ALTER TABLE `orderDetail` 208 | ADD CONSTRAINT `orderdetail_ibfk_2` FOREIGN KEY (`goodsId`) REFERENCES `goods` (`goodsId`); 209 | 210 | -- 211 | -- Constraints for table `orders` 212 | -- 213 | ALTER TABLE `orders` 214 | ADD CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `users` (`userid`); 215 | 216 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 217 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 218 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 219 | --------------------------------------------------------------------------------