public int countTotalData(String sql) {
try {
conn = DbConn.getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if(rs.next()){
return Integer.parseInt(rs.getString(1).toString());
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
DbConn.close(conn, rs, ps);
}
return 0;
}
@Override
public List<Object> queryList(String l_sql, int start, int end,BaseDaoImpl obj) {
try {
String sql = "SELECT * FROM(SELECT A.*, ROWNUM RN FROM ("+l_sql+") A WHERE ROWNUM <= "+end+") WHERE RN > "+start;
logger.info("查询数据的sql语句:"+sql);
@SuppressWarnings("unchecked")
List<Object> items = (List<Object>) jdbcTemplate.query(sql,obj);
if(items.isEmpty()){
return null;
}
return items;
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
DbConn.close(conn, rs, ps);
}
}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%"><div align="left"><span class="STYLE22"> 共有<strong><s:property value="pageBean.maxrowcount"/></strong> 条记录,当前第<strong><s:property value="pageBean.curpage"/></strong> 页,共 <strong><s:property value="pageBean.maxpage"/></strong> 页,每页 <strong><s:property value="pageBean.pagerowcount"/></strong> 行</span></div></td>
<td width="50%"><table width="180" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<s:if test="%{pageBean.curpage == 1}">
<td width="30"><div align="center"><img src="../images/first1.gif" width="30" height="20" alt="首页" border="0"/></div></td>
<td width="30"><div align="center"><img src="../images/pre1.gif" width="30" height="20" alt="上一页" border="0"/></div></td>
</s:if><s:else>
<td width="30"><div align="center"><A HREF="<s:property value="reqTitle"/>pageBean.page=1" ><img src="../images/first1.gif" width="30" height="20" alt="首页" border="0"/></a></div></td>
<td width="30"><div align="center"><A HREF="<s:property value="reqTitle"/>pageBean.page=<s:property value="%{pageBean.curpage-1}"/>&pageBean.curpage=<s:property value="%{pageBean.curpage}"/>"><img src="../images/pre1.gif" width="30" height="20" alt="上一页" border="0"/></A></div></td>
</s:else>
<td width="22"><div align="center">
<s:bean name="org.apache.struts2.util.Counter" id="counter">
<s:param name="first" value="1" />
<s:param name="last" value="%{pageBean.maxpage}" />
<SELECT name="jumpPage" onchange="Jumping(this.value)">
<s:iterator status="count">
<s:if test="%{pageBean.curpage == #count.index +1}">
<OPTION value="<s:property/>" selected="selected"><s:property/></OPTION>
</s:if>
<s:else>
<OPTION value="<s:property/>"><s:property/></OPTION>
</s:else>
</s:iterator>
</SELECT>
</s:bean>
</div></td>
<s:if test="%{pageBean.curpage >= pageBean.maxpage}">
<td width="30"><div align="center"><img src="../images/next1.gif" width="30" height="20" alt="下一页" border="0"/></div></td>
<td width="30"><div align="center"><img src="../images/last1.gif" width="30" height="20" alt="最后一页" border="0"/></div></td>
</s:if><s:else>
<td width="30"><div align="center"><A HREF="<s:property value="reqTitle"/>pageBean.page=<s:property value="%{pageBean.curpage+1}"/>&pageBean.curpage=<s:property value="%{pageBean.curpage}"/>"><img src="../images/next1.gif" width="30" height="20" alt="下一页" border="0"/></A></div></td>
<td width="30"><div align="center"><A HREF="<s:property value="reqTitle"/>pageBean.page=<s:property value="pageBean.maxpage"/>"><img src="../images/last1.gif" width="30" height="20" alt="最后一页" border="0"/></A></div></td>
</s:else>
</tr>
</table></td>
</tr>
</table>
本文介绍了一种基于SQL的分页查询实现方法,并通过具体代码示例展示了如何进行总记录数的统计及分页数据的获取。同时,还提供了一个包含页面导航和跳转功能的HTML模板。
1474

被折叠的 条评论
为什么被折叠?



