Home > Database > Mysql Tutorial > 数据库连接池

数据库连接池

WBOY
Release: 2016-06-07 15:36:03
Original
1447 people have browsed it

计算确定数据表一共分几页:101/pageSize=100/10=10页。rows = select count(1) from users;方法1:pageCount = rows/pageSize + (rows%pageSize==0?0:1); 方法2:pageCount = (rows+ (pageSize-1))/(pageSize);public void doGet(HttpServletRequest req,

<span>计算确定数据表一共分几页:
	101/pageSize=100/10=10页。
	rows = select count(1) from users;
	方法1:pageCount = rows/pageSize + (rows%pageSize==0?0:1);
  方法2:pageCount = (rows+ (pageSize-1))/(pageSize);
public void doGet(HttpServletRequest req, HttpServletResponse response)
			throws ServletException, IOException {
		//第一步:定义每页显示多少行
		int pageSize = 10;
		try{
			//第二步:获取数据表中有多少行
			QueryRunner run = new QueryRunner(DataSourceUtils.getDatasSource());
			String sql = "select count(*) from users";
			Object o = run.query(sql,new ScalarHandler());
			int rows = Integer.parseInt(o.toString());
			//第三步:计算一共分多少页
			int pageCount= rows/pageSize+(rows%pageSize==0?0:1);
			//将页数放到req
			req.setAttribute("pageCount",pageCount);
			
		}catch(Exception e){
			e.printStackTrace();
		}
		//转发到
		req.getRequestDispatcher("/jsps/show.jsp").forward(req, response);
		
	}
</span>
Copy after login

第四步:分析limit的开始位置

用户请求的面码

start

算法:

1

Limit 0,pageSize

Start

= (currentPage-1)*pageSize

2

Limit 10,pageSize

3

Limit 20,pageSize

 

第五步:对分页以后页码再分页

       每个页面,最多显示10个页码

       pageNum=10;

startNo

endNo

 

当前页码

页码范围

算法

1

1~10

If(currentPage

  1~10

2

 

3

 

4

 

5

 

6

2~11

6-4=2 =

6-(pageNum/2-1)=2 = startNo

endNo = startNo+(pageNum-1)=11

7

3~12

8

4~13

9

 

 

10

 

 

11

 

11-4 = 7

endNo = 7+9=16

endNo = 11;

startNo = 2 = endNo-(pageNum-1);

 

 

 

 

 

 

 

 

 

 


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template