四种分页的写法--4月27号

1.连接数据库,写sql语句(sql server)。

获得总记录数:rs = statement.executeQuery(select count(*) from article where pid =0) ;

rs.next();

int totalrecord = rs.getInt(1);

获得总页数 totalpage = totalrecord % pageSize ==0 ? totalrecord/pageSize : totalrecord/pageSize +1;

假如每一页显示n个,第m页的记录是: select top n  * from article where pid = 0 and id not in 

(select top n*(m-1) id from article where pid = 0 order by pdate)

order by pdate;

2.前一页,后一页分页跳转

共<%=totalpage %>页 ,当前第<%= pageNo %>页

<a href="ShowArticleFlag.jsp?pageNo=<%=pageNo-1 %> " > 上一页 </a>

扫描二维码关注公众号,回复: 2404117 查看本文章

<a href="ShowArticleFlag.jsp?pageNo=<%=pageNo+1 %> " > 一页 </a>

3.选择框跳转页面

<form name = "form1"  action="ShowArticleFlag.jsp">

<select name="pageNo" onchanged="document.form1.submit()" >

<% for(int i = 1;i<= totalpage;i++){ %>

<option value="<%=i %>"   "<%= pageNo==i?selected:"" %> > 第<%=i %>页</option>

<% } %></select></form>

4.文本框跳转页面

<form name="form1" action = "ShowArticleFlag.jsp" >

<input type="text" name = "pageNo" size="2" />

<input type="submit" value="提交" />

</form>

5.页数显示跳转

<form>

<% for(int i = 1;i<=totalpage;i++ ){

if(i=pageNo){ %>

<%=i %>

<% else { %>

<a href="ShowArticleFlag.jsp?pageNo=<%=i %>" ><%=i></a>

<%}

} %>


//还缺点,明天在写啦,今天太累了

猜你喜欢

转载自blog.csdn.net/x3499633/article/details/70941810