分页

package com.jtv.oaquery.module.forumreply.entity;


import java.util.List;


/**
 * 分页的Page类
 * @version 2016-11-01 
 * @author liuyy 
 */
@SuppressWarnings("unchecked")
public class Page {


// 传递的参数或配置的值
private int currentPage; // 当前页
private int pageSize = 10; // 每页显示多少条记录


// 查询数据库
private int recordCount; // 总记录数
private List recordList; // 本页的数据列表


// 计算
private int pageCount; // 总页数
private int beginPageIndex; // 页码列表的开始索引
private int endPageIndex; // 页码列表的结束索引


/**
* 只接受4个必要的属性值,会自动的计算出其他3个属性的值

* @param currentPage
* @param pageSize
* @param recordCount
* @param recordList
*/
public Page(int currentPage, int pageSize, int recordCount, List recordList) {
this.currentPage = currentPage;
this.pageSize = pageSize;
this.recordCount = recordCount;
this.recordList = recordList;


// 计算 pageCount
this.pageCount = (recordCount + pageSize - 1) / pageSize;


// 计算beginPageIndex与endPageIndex
// 1、总页码数<=10,就全部显示
if (pageCount <= 10) {
beginPageIndex = 1;
endPageIndex = pageCount;
}
// 2、总页码数>10
else {
// 1,显示当前页附近的共10个页码(前4个+当前页+后5个)
beginPageIndex = currentPage - 4;
endPageIndex = currentPage + 5;
// 2,前面不足4个页码时,显示前10个页码
if (beginPageIndex < 1) {
beginPageIndex = 1;
endPageIndex = 10;
}
// 3,后面不足5个页码时,显示后10个页码
else if (endPageIndex > pageCount) {
endPageIndex = pageCount;
beginPageIndex = pageCount - 9; // 因为显示时包含两个边界,所以这里要减9。
}
}


}


public List getRecordList() {
return recordList;
}


public void setRecordList(List recordList) {
this.recordList = recordList;
}


public int getCurrentPage() {
return currentPage;
}


public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}


public int getPageCount() {
return pageCount;
}


public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}


public int getPageSize() {
return pageSize;
}


public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}


public int getRecordCount() {
return recordCount;
}


public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}


public int getBeginPageIndex() {
return beginPageIndex;
}


public void setBeginPageIndex(int beginPageIndex) {
this.beginPageIndex = beginPageIndex;
}


public int getEndPageIndex() {
return endPageIndex;
}


public void setEndPageIndex(int endPageIndex) {
this.endPageIndex = endPageIndex;
}


}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<%@page import="cn.com.jtv.mf.core.beanutil.SpringBeanUtils"%>

<%@page import="cn.com.jtv.mf.core.web.LoginUserHolder"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/mf/include/manager.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
pageContext.setAttribute("ctx", request.getContextPath());
String userName = LoginUserHolder.getUserName();
/* AuthorityManager authorityManager = SpringBeanUtils.getBean("authorityManager");
pageContext.setAttribute("isSuperAdmin", authorityManager.isSuperAdmin()); */
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查看主题:${topic.topicTitle }</title>
<link type="text/css" rel="stylesheet" href="${ctx}/project/css/forum.css" />
<link type="text/css" rel="stylesheet" href="${ctx}/project/css/page.css" />
<script type="text/javascript" src="${ctx}/thirdparty/jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="${ctx}/mf/script/core.js"></script>
<script type="text/javascript" src="${ctx}/mf/script/action.js"></script>
<script type="text/javascript" src="${ctx}/thirdparty/ckeditor/ckeditor.js"></script>
<script>
mf.request={ctxPath:"${ctx}", actionPath:"${ctx}${actionPath}","isSuperAdmin":${isSuperAdmin}};
</script>


<script type="text/javascript">
$(function() {
//当没有回复数据的时候pageCount为0时显示第一页
var pageCount = ${page.pageCount == 0 ? 1 : page.pageCount};
//总条数是10的倍数并且不是第一页的时候代表最后一页也是10条,让pageCount加1
if(${page.recordCount % 10 == 0} && ${page.currentPage != 1}) {
pageCount = pageCount + 1;
}

document.forms[0].action = "${ctx}/oaquery/forumtopic.do?method=saveForumReply&pageNum="+ pageCount;
})
</script>


</head>
<body>
<div id="MainArea">

<center>

<div class="ForumPageTableBorder dataContainer">

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="bottom">
<td width="3" class="ForumPageTableTitleLeft">&nbsp;</td>
<td class="ForumPageTableTitle"><b>本帖主题:${topic.topicTitle}</b></td>
</tr>
<tr height="1" class="ForumPageTableTitleLine"><td colspan="4"></td></tr>
</table>

<!-- ~~~~~~~~~~~~~~~ 显示主帖(主帖只在第1页显示) ~~~~~~~~~~~~~~~ -->
<c:if test="${page.currentPage == 1}">
<div class="ListArea">
<table border="0" cellpadding="0" cellspacing="1" width="100%">
<tr>
<td rowspan="3" width="130" class="PhotoArea" align="center" valign="top">
<!--作者头像-->
<div class="AuthorPhoto">
<img border="0" width="110" height="110" src="${ctx}/project/images/default.gif" 
οnerrοr="this.οnerrοr=null; this.src='${ctx}/project/images/default.gif';" />
</div>
<!--作者名称-->
<div class="AuthorName">${topicUser.userName}</div>
</td>

<td align="center">
<ul class="TopicFunc">
<!-- 文章表情与标题 -->
<li class="TopicSubject">
主题:${topic.topicTitle}
</li>
</ul>
</td>
</tr>

<tr>
<td valign="top" align="center">
<div class="Content">${topic.topicContent}</div>
</td>
</tr>

<tr><!--显示楼层等信息-->
<td class="Footer" height="28" align="center" valign="bottom">
<ul style="margin: 0px; width: 98%;">
<li style="float: left; line-height:18px;"><font color=#C30000>[楼主]</font>
<fmt:formatDate value="${topic.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
</li>
</ul>
</td>
</tr>
</table>
</div>
</c:if>
<!-- ~~~~~~~~~~~~~~~ 主贴结束 ~~~~~~~~~~~~~~~ -->

<!---------显示回复列表 ----------->
<c:forEach items="${page.recordList}" var="reply" varStatus="status">

<div class="ListArea template">
<input type="hidden" id="userName" value="<%=userName %>"/>

<table border="0" cellpadding="0" cellspacing="1" width="100%">
<tr>
<td rowspan="3" width="130" class="PhotoArea" align="center" valign="top">
<!--回复人头像-->
<div class="AuthorPhoto">
<img border="0" width="110" height="110" src="${ctx}/project/images/default.gif" 
οnerrοr="this.οnerrοr=null; this.src='${ctx}/project/images/default.gif';" />
</div>

<!--回复人名称-->
<div class="AuthorName">${reply.replyUserName}</div>
</td>


<td align="center">
<ul class="TopicFunc">
<!--操作列表-->
<li class="TopicFuncLi">
<a class="detail${status.count}" href="javascript:updateForumReply('${reply.replyId}','${topic.topicId }','${page.currentPage}')"><img border="0" src="${ctx}/project/images/edit.gif" />修改</a>
<a class="detail${status.count}" href="javascript:deleteForumReply('${reply.replyId}','${topic.topicId }','${page.currentPage}')"><img border="0" src="${ctx}/project/images/delete.gif" />删除</a>
</li>
<li class="TopicSubject">
回复:${topic.topicTitle}
</li>
</ul>

<!-- 根据当前的回复是谁创建的来动态的显示修改和删除的超链接 -->
<script type="text/javascript">

$(function() {
var userName = $("#userName").val();
var replyAuthor = '${reply.replyUserName}';

if(${isSuperAdmin}) {
return true;
}

if(userName != replyAuthor) {
//当前页面上有多个人回复的时候为了让对应登录人的显示,所以写了下列的选择器
$(".detail${status.count}").hide();
}
})

</script>

</td>

</tr>
<tr><!-- 文章内容 -->
<td valign="top" align="center">
<div class="Content">${reply.replyContent}</div>
</td>
</tr>
<tr><!--显示楼层等信息-->
<td class="Footer" height="28" align="center" valign="bottom">
<ul style="margin: 0px; width: 98%;">
<li style="float: left; line-height:18px;"><font color=#C30000>[${(page.currentPage - 1) * (page.pageSize) + status.count}楼]</font>
   <fmt:formatDate value="${reply.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
</li> 
</ul>
</td>
</tr>
</table>

</div>

</c:forEach>

<!-- ~~~~~~~~~~~~~~~ 显示回复列表结束 ~~~~~~~~~~~~~~~ -->
</div>


<div id="PageSelectorBar">
<div id="PageSelectorMemo">
页次:${page.currentPage}/${page.pageCount == 0 ? 1 : page.pageCount } 页 &nbsp;
每页显示:${page.pageSize}条&nbsp;
回复总记录数:${page.recordCount}条
</div>
<div id="PageSelectorSelectorArea">
<a href="javascript:gotoPage('${topic.topicId}',1)" title="首页" style="cursor:pointer;">
<img src="${ctx}/project/images/firstPage.png">
</a>

<!-- 遍历显示页码的操作,${num}获取当前页 -->
<c:forEach begin="${page.beginPageIndex}" end="${page.endPageIndex}" var="num">
<c:choose>
<c:when test="${page.currentPage == num }">
<span class="PageSelectorNum PageSelectorSelected">${num}</span>
</c:when>

<c:otherwise>
<span class="PageSelectorNum" style="cursor:pointer;" οnclick="gotoPage('${topic.topicId}','${num}')">${num}</span>
</c:otherwise>
</c:choose>
</c:forEach>

<a href="javascript:gotoPage('${topic.topicId}','${page.pageCount}')" title="尾页" style="cursor:pointer;">
<img src="${ctx}/project/images/lastPage.png">
</a>

转到:
<select id="pn" οnchange="gotoPage('${topic.topicId}',this.value)">
<c:forEach begin="1" end="${page.pageCount == 0 ? 1 : page.pageCount}" var="num">
<option value="${num}">${num}</option>
</c:forEach>
</select>

<script type="text/javascript">
$("#pn").val(${page.currentPage});
</script>

</div>
</div>

<script type="text/javascript">

//跳转到页码的操作
function gotoPage(topicId,pageNum) {
window.location.href = "${ctx}/oaquery/forumtopic.do?method=getAllTopic&topicId="+topicId+"&pageNum="+pageNum;
}

//删除回复的操作
function deleteForumReply(replyId,topicId,pageNum) {
var flag = confirm("确定要删除此回复吗?");

if(flag) {
//当页面上面只有一条记录的时候这个时候点击删除,会跳转到当前页面的前面的一页
if(${page.currentPage} == ${page.endPageIndex} &&  ${page.recordList.size() == 1} && ${page.currentPage != 1}) {
var pageNum = ${page.currentPage - 1 };
window.location.href = "${ctx}/oaquery/forumtopic.do?method=deleteForumReply&replyId="+replyId+"&topicId="+topicId+"&pageNum="+pageNum;
}else{
window.location.href = "${ctx}/oaquery/forumtopic.do?method=deleteForumReply&replyId="+replyId+"&topicId="+topicId+"&pageNum="+pageNum;
}
}
}

//修改回复的操作
function updateForumReply(replyId,topicId,pageNum) {
window.location.href = "${ctx}/oaquery/forumtopic.do?method=updateForumReply&replyId="+replyId+"&topicId="+topicId+"&pageNum="+pageNum;

}

</script>

<div class="ForumPageTableBorder" style="margin-top: 25px;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="bottom">
<td width="3" class="ForumPageTableTitleLeft">&nbsp;</td>
<td class="ForumPageTableTitle"><b>回复</b></td>
<td width="3" class="ForumPageTableTitleRight">&nbsp;</td>
</tr>
<tr height="1" class="ForumPageTableTitleLine">
<td colspan="3"></td>
</tr>
</table>
</div>

</center>

<div class="QuictReply">

<form method="post">
<input type="hidden" name="topicId" value="${topic.topicId }"/>

<div style="padding-left: 3px;">
<table border="0" cellspacing="1" width="98%" cellpadding="5" class="TableStyle">
<tr height="30" class="Tint">
<td width="50px" class="Deep"><b>标题:</b></td>
<td class="no_color_bg">
<input type="text" name="title" class="InputStyle" value="回复:${topic.topicTitle}" style="width:100%" disabled="true"/>
</td>
</tr>
<tr class="Tint" height="200">
<td valign="top" rowspan="2" class="Deep"><b>内容:</b></td>
<td valign="top" class="no_color_bg">
<textarea name="replyContent" style="width: 95%; height: 200px"></textarea>
<script type="text/javascript">
CKEDITOR.replace('replyContent');
</script>
</td>
</tr>
<tr height="30" class="Tint">
<td class="no_color_bg" colspan="2" align="center">
<input type="image" src="${ctx}/project/images/submit.png" style="margin-right:15px;"/>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</div>
</body>
</html>

---------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
* 跳转到自定义的页面
* @date 2016-07-28 
*
*/
public ModelAndView getAllTopic() {    
String topicId = request.getParameter("topicId");
String num = request.getParameter("pageNum");
Integer pageNum = Integer.valueOf(num);
ForumTopic topic = getEntityManager().retrieve(ForumTopic.class, topicId);
ForumTopicManager forumTopicManager = (ForumTopicManager)getEntityManager();
//查询回复
Page page = forumTopicManager.getForumReply(pageNum,topicId);
MfUser topicUser = getTopicUser(topic);
ModelAndView mv = new ModelAndView();
mv.addObject("topic", topic);
mv.addObject("topicUser", topicUser);
mv.addObject("page", page);
String viewName = "/oaquery/module/forumtopic/forumtopicView.jsp";
mv.setViewName(viewName); 
return mv; 

--------------------------------------------------------------------------------------------------------------------
/**
* 根据 topicId获取当前页的回复
* @date 2016-07-28 
* @author liuyy
*/
@SuppressWarnings("unchecked")
public Page getForumReply(int pageNum,String topicId) {
int pageSize = 10;
//查询本页数据列表
List<ForumReply> replyList = getDao().getExtDao().getSession()
.createQuery("FROM ForumReply r WHERE r.topicId=? ORDER BY r.replyNum ASC")
.setParameter(0, topicId)
.setFirstResult((pageNum -1) * pageSize)
.setMaxResults(pageSize)
.list();
//查询总记录数
Long count = (Long) getDao().getExtDao().getSession()
.createQuery("SELECT COUNT(*) FROM ForumReply r WHERE r.topicId=?")
.setParameter(0, topicId)
.uniqueResult();

return new Page(pageNum, pageSize, count.intValue(), replyList);
}


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值