javaWeb购物商城设计---商品显示
商品显示包括显示两条热门商品,12条最新商品和12条打折商品。
数据库连接设计见//blog.csdn.net/u013948010/article/details/78675348
数据库
后台数据库用到了sql server,建立了商品表tb_goods和商品分类表tb_subType
商品分类表:
商品表:
获得最新商品
/* 最新上架商品信息 */
ResultSet rs_new = conn.executeQuery(
"select top 12 t1.ID, t1.GoodsName,t1.price,t1.picture,t2.TypeName "
+"from tb_goods t1,tb_subType t2 where t1.typeID=t2.ID and "
+"t1.newGoods=1 order by t1.INTime desc"); //查询最新上架商品信息
int new_ID=0; //保存最新上架商品的id变量
String new_goodsname=""; //保存最新上架商品名称的变量
float new_nowprice=0; //保存最新上架商品的价格变量
String new_picture=""; //保存最新上架商品的图片变量
String typeName=""; //保存最新上架商品的分类变量
前端页面循环显示
<!-- 循环显示最新上架商品 :添加12条商品信息-->
<%
while(rs_new.next()){
new_ID=rs_new.getInt(1); //最新上架商品的id
new_goodsname=rs_new.getString(2); //最新上架商品的名称
new_nowprice=rs_new.getFloat(3); //最新上架商品当前价格
new_picture=rs_new.getString(4); //最新上架商品的图片
typeName=rs_new.getString(5); //最新上架商品的类别
%>
<!--循环显示的html代码-->
<%}%>
获得打折商品
ResultSet rs_sale = conn.executeQuery(
"select top 12 t1.ID, t1.GoodsName,t1.price,t1.nowPrice,t1.picture,t2.TypeName "
+"from tb_goods t1,tb_subType t2 where t1.typeID=t2.ID and t1.sale=1 "
+"order by t1.INTime desc"); //查询打折商品信息
int sale_ID=0; //保存打折商品的id变量
String s_goodsname=""; //保存打折商品名称的变量
float s_nowprice=0; //保存打折商品现在的价格变量
float s_price=0; //保存打折商品的原价格变量
String s_picture=""; //保存打折商品的图片变量
String s_introduce=""; //保存打折商品简介
前端显示
<!-- 循环显示打折商品 :添加12条商品信息-->
<%
while(rs_sale.next()){
sale_ID=rs_sale.getInt(1); //打折商品的id
s_goodsname=rs_sale.getString(2); //打折商品的名称
s_price=rs_sale.getFloat(3); //打折商品原价格
s_nowprice=rs_sale.getFloat(4); //打折商品当前价格
s_picture=rs_sale.getString(5); //打折商品的图片
typeName=rs_sale.getString(6); //最新上架商品的类别
%>
<!--循环显示的html代码-->
<%}%>
获得两条热门商品
查询数据库并得到结果
ResultSet rs_hot =conn
.executeQuery("select top 2 ID,GoodsName,nowprice,picture "
+"from tb_goods order by hit desc"); //查询热门商品信息
int hot_ID = 0; //保存热门商品ID的变量
String hot_goodsName = ""; //保存热门商品名称的变量
float hot_nowprice = 0; //保存热门商品价格的变量
String hot_picture = ""; //保存热门商品图片的变量
前端显示:
<!-- 循环显示热门商品 :添加两条商品信息-->
<%
while(rs_hot.next()){
hot_ID=rs_hot.getInt(1); //获取热门商品id
hot_goodsName=rs_hot.getString(2); //获取热门商品名
hot_nowprice=rs_hot.getFloat(3); //热门商品当前价格
hot_picture=rs_hot.getString(4); //热门商品图片
%>
<!--循环显示的html代码-->
<%}%>
还没有评论,来说两句吧...