帮忙看看这个分页有没有BUG?
MSSQL mssql = new MSSQL();
Connection conn = mssql.getConn();
boolean isDesc = true;//是否倒序
int nRsCount = 0;//总记录数
int nPageCount = 0;//总页数
int nCurrentPage = 1;//当前页数
int nRsPage = 10;//每页记录数
//默认为顺序排列
String orderA = "asc";
String orderB = "desc";
if(isDesc){
orderA = "desc";
orderB = "asc";
}
if( null != request.getParameter("page") ){
nCurrentPage = Integer.parseInt(request.getParameter("page"));
}
PreparedStatement pstmt = conn.prepareStatement("select count(*) from employee");
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
nRsCount = Integer.parseInt(rs.getString(1));
}
nPageCount = nRsCount / nRsPage ;
int mark = nRsCount % nRsPage;
if( mark > 0){
nPageCount++;
}
if( nCurrentPage > nPageCount){
nCurrentPage = nPageCount;
}
String sql = "select * from (select top "+ nRsPage +" * from (select top "+ nCurrentPage*nRsPage +" * from (select emp_id,fname,hire_date from employee) a order by 3 "+ orderA +" ) b order by 3 "+ orderB +") c order by 3 "+ orderA +"";
if( nCurrentPage == nPageCount){ //最后一页
int nEnd = nRsCount - (nPageCount-1)*nRsPage;
sql = "select * from (select top "+ nEnd +" * from (select top "+ nCurrentPage*nRsPage +" * from (select emp_id,fname,hire_date from employee) a order by 3 "+ orderA +" ) b order by 3 "+ orderB +") c order by 3 "+ orderA +"";
}
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
out.println(rs.getString(1)+"<br>");
}
%>
总共 <%=nPageCount%> 页
<%
for(int i=1;i<=nPageCount;i++){
%>
<a href="index.jsp?page=<%=i%>"><%=i%></a>
<% } %>
...全文
相关推荐
jquery分页 纯前端分页 修改部分bug,利于调用
jquery分页 纯前端分页 修改部分bug
修复Ext3.0.0中自定义分页的小bug
NULL 博文链接:https://sweetrain369.iteye.com/blog/493135
sharding-jdbc 3.1.0 不分片表,分页bug,第二页查出的数据会显示前面的数据
sharding-jdbc 3.1.0 不分片表,分页bug,第二页查出的数据会显示前面的数据 https://github.com/apache/incubator-shardingsphere/issues/1722 sharding-core-3.1.0.jar
Java 外包实战代码包|分页 CRUD+Bug 修复 + 通用工具类
10 年外包 Java 整理,直接复制运行,解决 80% 日常开发问题,少踩坑、少加班,外包同行必备!
javascript分页
今天发现项目中的分页工具不是很好用,而且还有bug,于是乎自己写了一个,感觉还可以吧


Web 开发

