三层架构——购物车

//三层架构是什么?

首先呢?通常意义上三层架构就是将整个业务应用划分为:界面(或表示)层,业务逻辑层,数据访问层。分层式结构是最常见的也是一种最重要的结构。

1.那么什么是数据访问层?

        就是数据访问层在作业过程中访问数据系统中的文件实现对数据库中数据的读取保存操作。

2.什么是业务逻辑层?

        将用户的输入信息进行甄别处理,分别保存。建立新的数据储存方式,在存储过程中对数据       进行读取,将“商业逻辑”描述代码进行包含。

3.什么是表示层?

        主要功能是显示数据和接收传输用户的数据,可以在为网站的系统运行提供交互式操作界面,表示层的应用方式比较常见,例如Windows窗体和web页面。

//看看我的eclipse所需要的Java文件(便于自己进行操作建立需要的Java文件)

 //然后看看部分的Javaee代码(这个是主界面)

function gm(bid) {
	//跳转到do页面 顺便传个编号
	alert(bid);
	location.href="dogwc.jsp?bid="+bid;
}
</script>
</head>
<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>

//效果图如下 

//添加至购物车是重要的dm,可供参考

//判断用户是不是为空
Object obj = session.getAttribute("a");
if(obj==null){
	out.print("<script>alert('你没有登录,请先登录');location.href='login.jsp'</script>");
}

//获取商品订单的数量
String number =request.getParameter("gn");
int count=1;
if(number!=null){
	count=Integer.valueOf(number);
}
//接受商品的编号
int bid=Integer.valueOf(request.getParameter("bid"));
IOrderItemBiz ss=new Imp_OrderItemBiz();
GoodsBiz se=new Imp_GoodsBiz();
double jg= se.getById(bid).getBprice();
//给属性赋值
User sf=(User)session.getAttribute("a");
OrderItem oi=new OrderItem(sf.getSuid(),bid,1,1.0,"下单成功");

//获取OrderItem中的订单集合
ArrayList<OrderItem> olist=ss.getAll(sf.getSuid());
boolean b=true;//表示默认 没有相同的订单
double SumPrice=0;
//遍历订单集合,判断是否已存在相同商品订单
for(int i=0;i<olist.size();i++){
	if(bid==olist.get(i).getBid()){
		//number为空说明是从index页面过来的
		if(number==null){
			//修改数量:原来的数量+1
			boolean wdw=ss.updateByOid(olist.get(i).getOid(),olist.get(i).getGnumber()+1,jg);
		if(wdw){
			JOptionPane.showMessageDialog(null, "商品添加成功");
		}else{
			JOptionPane.showMessageDialog(null, "商品添加成功");
		}
		}else{//number为空说明是从spcar页面过来的
			//修改数量:原来的数量修改为count
			boolean wdw=ss.updateByOid(olist.get(i).getOid(),count,jg);
			if(wdw){
				JOptionPane.showMessageDialog(null, "商品添加成功");
			}else{
				JOptionPane.showMessageDialog(null, "商品添加成功");
			}
			
		}
		
	b=false;
	}
}
if(b){
	//把订单放到orderitem表中
	GoodsBiz gd=new Imp_GoodsBiz();
	Goods s=gd.getById(bid);
	boolean sfc=ss.taddId(oi,s.getBprice());
	if(sfc){
		JOptionPane.showMessageDialog(null, "商品添加成功");
	}else{
		JOptionPane.showConfirmDialog(null, "商品添加成功");
	}
	
}

//跳转页面
response.sendRedirect("spcar.jsp");
%>

 

 //功能嘛其实就是调用Java中dao以及接口方法。(我就给一个登录的代码吧)

<% 
	String uname=request.getParameter("textyh");
	String upwd=request.getParameter("pastmm");
	
	System.out.print(uname);	
	
	User u=new Imp_UserDao().login(uname, upwd);
	if(u!=null){
		session.setAttribute("u", u);
		request.getRequestDispatcher("index.jsp").forward(request, response);
		}else{//错误就回到登录页面
		out.print("<script>alert('用户名或密码错误,请重新登录');location.href='login.jsp'</script>");
		//out.print(u);
	
	}
%>

//看看登录效果图吧!!

 

 

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值