根据前面的一个代码Page和PaginationHelper类可以查出第几页的数据返回一个List
Servlet层:
- // 分析当前页码
-
String pageString=req.getParameter("page");
-
if(pageString == null || pageString.length() == 0) {
-
pageString = "1";
-
}
-
int currentPage= 0 ;
-
try {
-
currentPage = Integer.parseInt(pageString);// 当前页码
-
} catch(Exception e) {}
-
if(currentPage == 0) {
-
currentPage = 1;
-
}
-
int pageSize = 30;//每页显示的数据数
-
-
PaginationHelper<EipSms> ph = new PaginationHelper<EipSms>();
-
List<EipSms> ls=new ArrayList<EipSms>();
-
Page<EipSms> p=ph.fetchPage(
-
jdbc,
-
"SELECT COUNT(*) FROM EIP_SMS WHERE CUSERID=? AND STATUS='1'",
-
"SELECT PK_EIP_SMS,RUSER,CONTENT,CTIME FROM EIP_SMS WHERE CUSERID=? AND STATUS='1'",
-
new Object[]{pageUser.getUserID()},
-
currentPage,
-
pageSize,
-
new ParameterizedRowMapper<EipSms>() {
-
public EipSms mapRow(ResultSet rs, int i) throws SQLException {
-
return new EipSms(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4));
-
}
-
}
-
);
-
ls=p.getPageItems();
-
req.getSession().setAttribute("ls",ls);// 保存列表
-
req.getSession().setAttribute("totalPage", p.getPagesAvailable());// 保存总页数
-
req.getSession().setAttribute("currentPage", currentPage);// 保存当前页码
-
-
res.sendRedirect("resources/sms/sms_draft.jsp");
表现层:
- <td>
-
<%-- 输出页面跳转代码, 分链接和静态文字两种 --%>
-
<c:if test="${currentPage > 1}">
-
[ <a href="${pageContext.request.contextPath}/showsms?type=draft&page=${currentPage-1}">上一页</a> ]
-
</c:if>
-
<c:if test="${currentPage <= 1}">
-
[ 上一页 ]
-
</c:if>
-
<c:if test="${currentPage < totalPage}">
-
[ <a href="${pageContext.request.contextPath}/showsms?type=draft&page=${currentPage+1}">下一页</a> ]
-
</c:if>
-
<c:if test="${currentPage >= totalPage}">
-
[ 下一页 ]
-
</c:if>
-
<%-- 输出 JavaScript 跳转代码 --%>
-
<script>
-
// 页面跳转函数
-
// 参数: 包含页码的表单元素,例如输入框,下拉框等
-
function jumpPage(input) {
-
// 页码相同就不做跳转
-
if(input.value == ${currentPage}) {
-
return;
-
}
-
var newUrl = "${pageContext.request.contextPath}/showsms?type=draft&page=" + input.value;
-
document.location = newUrl;
-
}
-
</script>
-
转到
-
-
<select onchange='jumpPage(this);'>
-
<c:forEach var="i" begin="1" end="${totalPage}">
-
<option value="${i}"
-
<c:if test="${currentPage == i}">
-
selected
-
</c:if>
-
>第${i}页</option>
-
</c:forEach>
-
</select>
-
</td>
-
-
//循环输出list
-
<c:forEach items="${ls}" var="sms" >
-
<tr>
-
<td></td>
-
<td><input type="checkbox" name="$$SelectDoc" value="${sms.pk_eip_sms}"></td>
-
<td><font size="2"><a href="" target="_blank">${sms.content}</a></font></td>
-
<td><font size="2">${sms.ctime}</font></td>
-
<td>${sms.ruser}</td>
-
</tr>
-
</c:forEach>
阅读(2850) | 评论(0) | 转发(0) |