1.登录页面
create table OrderItem
(
oid number,
uuid number,
bid number,
bname varchar2(200),
bprice number,
binfo varchar2(200),
bface varchar2(200),
gnumber number,
gsumprice number
)
alter table OrderItem
add constraint p_oid primary key (OID);
2.商品界面代码 index.jsp
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<table class="table table-hover">
<tr>
<td>商品编号</td>
<td>商品名称</td>
<td>商品单价</td>
<td>商品介绍</td>
<td>商品图片</td>
<td><span class="glyphicon glyphicon-cog"></span></td>
</tr>
<%
GoodsBiz gd=new Imp_GoodsBiz();
ArrayList<Goods> glist=gd.getAll();
for(Goods g:glist){
%>
<tr>
<td><%=g.getBid() %></td>
<td><%=g.getBname() %></td>
<td><%=g.getBprice() %></td>
<td><%=g.getBinfo() %></td>
<td><img alt="" src="<%=g.getBface()%>"></td>
<td><button onclick="gm(<%=g.getBid() %>)" class="btn btn-success">添加购物车</button>
</tr>
<%} %>
</table>
</body>
3.购物车界面
<%@page import="com.zking.biz.imp.Imp_GoodsBiz"%>
<%@page import="com.zking.biz.GoodsBiz"%>
<%@page import="com.zking.entity.Goods"%>
<%@page import="com.zking.entity.User"%>
<%@page import="com.zking.entity.OrderItem"%>
<%@page import="com.zking.biz.imp.Imp_OrderItemBiz"%>
<%@page import="com.zking.biz.IOrderItemBiz"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<script type="text/javascript">
function xg(obj,bjd) {
var gnumber=obj.value;
if(gnumber>0){
location.href="dogwc.jsp?bid="+bjd+"&gn="+gnumber;
}else if(gnumber<=0 ){
alert("商品数量不能<=0:");
location.href="dodele.jsp?bid="+bid;
}
}
function sc(bid) {
if(confirm("确定删除吗?")){
location.href="dodele.jsp?bid="+bid;
}
}
function ff(bid,i) {
var gnumber=document.getElementById(bid).value;
if(gnumber>0){
if(i==1){
gnumber--;
location.href="dogwc.jsp?bid="+bid+"&gn="+gnumber;
}else if(i==2) {
gnumber++;
location.href="dogwc.jsp?bid="+bid+"&gn="+gnumber;
}
}else if(gnumber<=0 ){
alert("商品数量不能<=0:");
location.href="dodele.jsp?bid="+bid;
}
}
</script>
</head>
<body>
<%
//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}
%>
<h1 align="center">
<a href="index.jsp"> <span class="glyphicon glyphicon-home"></span>
</a>
</h1>
<table class="table table-hover">
<tr>
<td>商品图片</td>
<td>商品名称</td>
<td>商品价格</td>
<td>商品介绍</td>
<td>商品数量</td>
<td>订单总价</td>
<td>订单时间</td>
<td>订单状态</td>
<td>操作一下</td>
</tr>
<%
// 获取到session中的订单集合
IOrderItemBiz ss=new Imp_OrderItemBiz();
GoodsBiz kj=new Imp_GoodsBiz();
Goods dd=null;
User sf=(User)session.getAttribute("a");
ArrayList<OrderItem> olist = ss.getAll(sf.getUuid());
//把订单绑定到页面
for (int i = 0; i < olist.size(); i++) {
dd=kj.getById(olist.get(i).getBid());
%>
<tr>
<td><img alt="" src="<%=dd.getBface()%>">
</td>
<td><%=dd.getBname()%></td>
<td><%=dd.getBprice()%></td>
<td><%=dd.getBinfo()%></td>
<td>
<button onclick="ff(<%=dd.getBid()%>,1)">-</button>
<input
onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}"
onblur="xg(this,<%=dd.getBid()%>)"
id="<%=dd.getBid()%>"
style='width: 40px; text-align: center;' type="text"
value="<%=olist.get(i).getGnumber()%>">
<button onclick="ff(<%=dd.getBid()%>,2)">+</button>
</td>
<td><%=olist.get(i).getGsumprice()%></td>
<td><%=olist.get(i).getOdate() %></td>
<td><%=olist.get(i).getOzt() %></td>
<td><button onclick="sc(<%=dd.getBid()%>)" class="glyphicon glyphicon-trash" >
</button></td>
</tr>
<%
}
%>
</table>
<p align="right" style="margin-rigth: 40px">
<button class="btn btn-success">
总价格:<%=ss.getsum() %></button>
</p>
</body>
</html>