SELECT * FROM product where cid = 1 LIMIT 0,5;
SELECT * FROM product where cid = 1 LIMIT 5,5;
SELECT * FROM product where cid = 1 LIMIT ?,?;
– 统计cid对应的有多少条数据
SELECT COUNT(*) FROM product where cid = 1;
2、原理
3、步骤实现
1、准备工作:
修改/jsp/header.jsp下的js里面的链接。
将当前页和对应商品的cid(商品id) 传入到对应的servlet
var li = “
- ”+obj.cname+“
- ”;
2、在productServlet当中创建findProductByCidWithPage方法
public String findProductsByCidWithPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
//获取cid,num
String cid = request.getParameter(“cid”);
int curNum = Integer.parseInt(request.getParameter(“num”));
//调用业务层功能:以分页形式查询当前类别下的商品
//返回PageModel对象(1、当前页信息 2、分页 3、url)
ProductService productService = new ProductServiceImpl();
PageModel pm = productService.findProductsByCidWithPage(cid,curNum);
//将pageModel对象放入到request当中
request.setAttribute(“page”, pm);
//转发到/jsp/product_list.jsp当中
return “/jsp/product_list.jsp”;
}
ScalarHandler: 将单个值封装
3、在ProductService当中创建对应的方法及其内容
创建PageModel对象目的:计算分页参数
统计当前分类下商品的个数 select count(*) from product where cid=?
关联集合 select * from product where cid = ? LIMIT ?,?
关联url
返回所有的分页数据以及对应的页码对象
&