Bootstrap

Java Web 网络商城案例演示十一(商品分页)

public Product() {

// TODO Auto-generated constructor stub

}

public Product(String pid, String pname, double market_price, double shop_price, String pimage, Date pdate,

String is_hot, String pdesc, int pflag, String cid) {

super();

this.pid = pid;

this.pname = pname;

this.market_price = market_price;

this.shop_price = shop_price;

this.pimage = pimage;

this.pdate = pdate;

this.is_hot = is_hot;

this.pdesc = pdesc;

this.pflag = pflag;

this.cid = cid;

}

@Override

public String toString() {

return “Product [pid=” + pid + “, pname=” + pname + “, market_price=” + market_price + “, shop_price=”

  • shop_price + “, pimage=” + pimage + “, pdate=” + pdate + “, is_hot=” + is_hot + “, pdesc=” + pdesc

  • “, pflag=” + pflag + “, cid=” + cid + “]”;

}

}

c3p0链接数据库

com.mysql.jdbc.Driver

jdbc:mysql://localhost:3306/store_07

root

root

30000

30

10

30

100

10

200

10

1

0

com.mysql.jdbc.Driver

jdbc:mysql://localhost:3306/store_07

root

root

5

20

10

40

0

5

/**

  • Servlet implementation class ProductServlet

*/

public class ProductServlet extends HttpServlet {

/**

  • @see HttpServlet#HttpServlet()

*/

public ProductServlet() {

super();

// TODO Auto-generated constructor stub

}

/**

  • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)

*/

/**

  • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

this.doPost(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//接收当前页

String num=request.getParameter(“num”);

int curNum=Integer.parseInt(num);

System.out.println(curNum);

ProductService ProductService=new ProductService();

//调用业务层查询当前页功能,返回PageModel对象(1_当前页数据2_分页参数)

PageModel pm=null;

try {

pm = ProductService.findProducts(curNum);

} catch (Exception e) {

e.printStackTrace();

}

//将PageModel对象放入request

request.setAttribute(“page”, pm);

//request.getRequestDispatcher(“/product_list.jsp”).forward(request, response);

request.getRequestDispatcher(“/product_list2.jsp”).forward(request, response);

}

}

public class ProductService {

public PageModel findProducts(int curNum) throws SQLException{

//1_创建PageModel对象 目的:计算分页参数

ProductDao ProductDao=new ProductDao();

int totalRecords=ProductDao.findToralRecords();

PageModel pm=new PageModel(curNum,5,totalRecords);//传入要点击的页数,和每页的页数,和对应总信息的条数

//2_关联数据 select * from product limit ? , ?

List list=ProductDao.findProducts(pm.getStartIndex(),pm.getPageSize());

pm.setList(list);

//3_关联url

pm.setUrl(“ProductServlet”);

return pm;

}

}

public class ProductDao {

//统计表中有多少条数据

public int findToralRecords() throws SQLException {

QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());

Long num=(Long)qr.query(“select count(*) from product”,new ScalarHandler());

return num.intValue();

}

public List findProducts(int startIndex, int pageSize) throws SQLException {

String sql="select * from product limit ? ,? ";

QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());

return qr.query(sql, new BeanListHandler(Product.class),startIndex,pageSize);

}

}

product_list.jsp

<%@ page language=“java” contentType=“text/html; charset=utf-8” pageEncoding=“utf-8”%>

<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>

Insert title here
商品名称 市场价格 商场价格 商品图片

<c:if test=“${empty page.list }”>

暂无数据

</c:if>

<c:if test=“${not empty page.list }”>

<c:forEach items=“${page.list}” var=“p”>

${p.pname} ${p.market_price} ${p.shop_price}

</c:forEach>

</c:if>

<%–分页显示的开始 --%>

p a g e . t o t a l P a g e N u m 页 / 第 {page.totalPageNum}页/第 page.totalPageNum/{page.currentPageNum}页

首页

<c:if test=“${page.currentPageNum != 1}”>

上一页

</c:if>

<%-- 获取开始结束页码

${page} *.getAttribute(“page”); 获取到pageModel对象

${page.startPage} 调用PageModel对象getStartPage()方法

–%>

<c:forEach begin=“ p a g e . s t a r t P a g e " e n d = " {page.startPage}" end=" page.startPage"end="{page.endPage}” var=“pagenum”>

<c:if test=“${page.currentPageNum==pagenum}”>

${pagenum}

</c:if>

<c:if test=“${page.currentPageNum!=pagenum}”>

${pagenum}

</c:if>

</c:forEach>

<c:if test=“${page.currentPageNum != page.totalPageNum}”>

下一页

</c:if>

末页

<%–分页显示的结束–%>

product\_list2.jsp

文末

逆水行舟不进则退,所以大家要有危机意识。

同样是干到35岁,普通人写业务代码划水,榜样们深度学习拓宽视野晋升管理。

这也是为什么大家都说35岁是程序员的门槛,很多人迈不过去,其实各行各业都是这样都会有个坎,公司永远都缺的高级人才,只用这样才能在大风大浪过后,依然闪耀不被公司淘汰不被社会淘汰。

为了帮助大家更好温习重点知识、更高效的准备面试,特别整理了《前端工程师核心知识笔记》电子稿文件。

内容包括html,css,JavaScript,ES6,计算机网络,浏览器,工程化,模块化,Node.js,框架,数据结构,性能优化,项目等等。

269页《前端大厂面试宝典》

包含了腾讯、字节跳动、小米、阿里、滴滴、美团、58、拼多多、360、新浪、搜狐等一线互联网公司面试被问到的题目,涵盖了初中级前端技术点。

前端面试题汇总

;