基于Struts的Oracle分页查询

来源:互联网 发布:新编直指算法统宗 编辑:程序博客网 时间:2024/06/06 13:19

                                        基于Struts的Oracle分页查询

  


// 计算总页数 count:总记录数 NumPerPage:每页显示的记录
public static int getPageCount(int count, int NumPerPage) {
return (count % NumPerPage == 0) ? (count / NumPerPage) : (count / NumPerPage + 1);
}

PageNum是自己设置的
// 当前页
private int pageNum = 1;

底层是
//查看所有的大分类  --分页   其中  pageNum 是当前页
public List<BigClass> findAllBigF(int pageNum) throws SysException {
List<BigClass> lb = new ArrayList<>();
//其中3 是自己设置的  每页想显示几条数据
String sql="SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM t_classtable) A)WHERE RN > ? AND RN<= ?";
Object obj []={(pageNum-1)*3,pageNum*3};
db.executeQuery(sql, obj);
List<Map<String, String>> ls = db.executeQuery(sql, obj);
for (int i = 0; i < ls.size(); i++) {
BigClass bc = new BigClass();
Map<String, String> map = ls.get(i);
int id = Integer.parseInt(map.get("ID"));
String name = map.get("NAME");
bc.setId(id);
bc.setName(name);
lb.add(bc);
}
return lb;
}

前台页面是
<body>
<div>
<div><img src="image/right_icon.jpg" />&nbsp;&nbsp;大分类管理</div>
<hr />
<div class="div_table">
<table class="div_table" border="1">
<tr>
<th width="140px">编号</th><th width="300px">分类名称</th><th width="140px">操作</th>
</tr>
<s:iterator value="lb">
<tr>
<td>${id }</td>
<td>${name}</td>
<td><a href="big_list!getObj.action?id=${id }" target="right">修改</a>&nbsp;<a class="delete" href="">删除</a></td>
</tr>
</s:iterator>




</table><br/>
<div>
<c:forEach begin="1" end="${pageCount}" step="1" var="p">
<c:if test="${pageNum == p }">
<c:out value="${p }"></c:out>
</c:if>
<c:if test="${pageNum != p }">
<a href="big_list!listF.action?pageNum=${p }" style="border-left: 1px">${p }</a>
</c:if>
</c:forEach>


</div>
0 0
原创粉丝点击