@wangzhuanyun
2017-07-06T15:13:56.000000Z
字数 3071
阅读 420
鸿卓国际
- /**
- * 商品类别实体类
- * @author john
- */
- @SuppressWarnings("serial")
- public class GoodsTypeInfo extends Model<GoodsTypeInfo> {
- public static GoodsTypeInfo dao = new GoodsTypeInfo();
- /**
- * 获取上商品类型集合
- * @return
- */
- public List<GoodsTypeInfo> getListGoodsTypeInfo()
- {
- //返回数据集合
- return GoodsTypeInfo.dao.find("select * from xxshop_goods_type ");
- }
- }
controller下代码如下:
添加方法名:getGoodsTypeInfoList
- /**
- * 获取商品分类
- */
- public void getGoodsTypeInfoList()
- {
- try {
- //商品分类
- List GoodsTypeInfoList = GoodsTypeInfo.dao.getListGoodsTypeInfo();
- //存入页面
- setAttr("GoodsTypeInfoList",GoodsTypeInfoList);
- render("/category.jsp");
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
引入JSTL标签库:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <!--
- forEach循环
- var 每次循环得到的对象(数据库查询后一行的数据集合)
- items ${放入存起来的名字}
- -->
- <c:forEach var="GoodsTypeInfo" items="${GoodsTypeInfoList}" >
- <a href="" class="list-group-item">
- ${GoodsTypeInfo.type_name} <!--type_name为数据库列名-->
- <span class="glyphicon glyphicon-chevron-right" style="float: right;"></span>
- </a>
- </c:forEach>
- #代码说明:
- 页面跳转href 中加入下面这段代码
- <%=basePath%>good/getClassListGoodsInfoList?type_name=${GoodsTypeInfo.type_name }&type_id=${GoodsTypeInfo.type_id}
- /**
- * 根据商品类型 获取商品信息
- * @param type_id 商品类型ID
- * @return
- */
- public List<GoodsInfo> getListGoodsInfo(long type_id)
- {
- String sql = "select a.*,(select images_url from xxshop_images where images_type =2 and goods_id=a.goods_id ) images_url from xxshop_goods a where a.type_id = ?";
- Object[] obj = new Object[]{type_id};
- return GoodsInfo.dao.find(sql,obj);
- }
controller下代码如下:
添加方法名:getClassListGoodsInfoList
- /**
- * 根据商品类型ID 获取商品集合信息
- */
- public void getClassListGoodsInfoList()
- {
- try {
- /*
- * 调用getListGoodsInfo方法
- * getParaToLong("type_id") 获取href中传过来的值
- */
- List<GoodsInfo> GoodsInfoList = GoodsInfo.dao.getListGoodsInfo(getParaToLong("type_id"));
- //吧type_name存起来
- setAttr("type_name",new String(getPara("type_name").getBytes("iso-8859-1"),"utf-8"));
- //吧获取的商品都存起来
- setAttr("GoodsInfoList",GoodsInfoList);
- //跳转商品列表集合页面
- render("/list.jsp");
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
引入JSTL标签库:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- 修改头部商品类型名称为:${type_name}
- <c:forEach var="GoodsInfo" items="${GoodsInfoList}" >
- <!--
- goodclick
- goods_id="${GoodsInfo.goods_id }"
- JQUERY使用
- -->
- <div class="col-xs-12 goodclick" goods_id="${GoodsInfo.goods_id }" style="background-color: #fff;padding: 10px;box-shadow: 0 9px 25px -8px rgba(0, 0, 0, 0.38);margin-top:5px">
- <div class="col-xs-4 text-center" style="padding:0px">
- //动态放入图片路径
- <img src="img/${GoodsInfo.images_url }" style="max-width: 100%">
- </div>
- <div class="col-xs-8 " >
- <div style="width: 100%;overflow:hidden; white-space:nowrap; text-overflow:ellipsis;">
- ${GoodsInfo.goods_name }//商品名称
- </div>
- <div style="width: 100%;font-size: 12px; color: #888;line-height: 20px;height: 10%">
- ${GoodsInfo.goods_title }//商品标题
- </div>
- <div style="width: 100%;text-align: right;">
- <span style="color:#00B8F1;font-size: 16px;line-height:30px;margin-right:5px">
- ¥${GoodsInfo.goods_money }//商品价格
- </span>
- </div>
- </div>
- </div>
- </c:forEach>
- #添加JQUERY代码:
- $(function(){
- //点击商品后触发跳转页面
- $(".goodclick").click(function(){
- location= '<%=basePath%>good/getGoodsInfo?goods_id='+$(this).attr("goods_id");
- });
- });