这篇文章主要为大家详细介绍了java实现分页的前台页面和后台代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了Java分页展示的具体代码,供大家参考,具体内容如下
先上图吧,大致如图,也就提供个思路(ps:使用了SSH框架)

前台JSP页面
html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>数据交易猫</title>
<script>
//1分页下,动态添加disable给分页按钮
/*
$(function(){
var myPageId="#"+$("#hidCurrentPage").val();
var myPageAId="#"+$("#hidCurrentPage").val()+" a";
$(myPageAId).addClass('main-bgcolor');
$(myPageAId).attr('href','javascript:void(0)')
$(myPageId).addClass('disabled');
$(myPageId).addClass('disabledControl');
})
*/
//
$(function(){
})
//根据页数查询数据列表
function queryRequirListByPage(i) {
var pageNo=i;
var sortValue=$('#hidSortValue').val();
$.ajax({
url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
type:'POST',
data:{
sortValue:sortValue,
pageNo:pageNo
},
success:function(datas){
$('#requireContentp').html(datas);
},
error:function(){
alert("失败");
},
});
}
//根据下拉查询数据列表
function selectPage(obj){
var pageNo=obj.options[obj.selectedIndex].value;
var sortValue=$('#hidSortValue').val();
$.ajax({
url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
type:'POST',
data:{
sortValue:sortValue,
pageNo:pageNo
},
success:function(datas){
$('#requireContentp').html(datas);
},
error:function(){
alert("失败");
},
});
}
//根据下拉选择排序方式
function selectSort(obj){
var sortValue = obj.options[obj.selectedIndex].value;
var pageNo =1;
$.ajax({
url:'${pageContext.request.contextPath}/bid/reAction_queryRequirListByPage.action',
type:'POST',
data:{sortValue:sortValue,
pageNo:pageNo
},
success:function(datas){
$('#requireContentp').html(datas);
},
error:function(){
alert("失败");
},
});
}
$(document).ready(function(){
var backSortValue=$('#backSortValue').val();
console.log("backSortValue"+backSortValue)
$("#category option").each(function(){
var thisId='#'+this.id;
var thisValue=this.value;
if(backSortValue==thisValue){
$(thisId).attr('selected','selected');
}
});
})
</script>
<!-- 内容-->
<p>
<!-- 标题-->
</p><p></p><h3>
<span></span>需求列表</h3>
<!-- 筛选条件-->
<p>
</p><p>
</p><p>
<span>筛选:按</span>
<select>
<option>最新</option>
<option>价格降序</option>
<input>
</select>
</p><hr>
<!-- 内容-->
<input>
<input>
<input>
<iterator>
<p>
</p>
<p>
</p>
<p>
</p>
<h4><a>${title}</a></h4>
<p>
</p>
<p>
</p>
<p>悬赏积分:<span>${price}</span></p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill11083" title="Java调试"><img
src="https://img.php.cn/upload/skill/001/246/273/6adaf20dbae7c507.jpg" alt="Java调试" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill11083" title="Java调试" class="overflowclass">Java调试</a>
<p class="overflowclass">通过 JDWP 实现 Java 远程调试:连接远程 JVM、设置断点、单步执行代码、查看变量值、获取调用栈。适用于需要调试远程 Java 应用、排查运行时状态、追踪代码执行流程的场景。
术语注解
JDWP:Java Debug Wire Protocol,Java 调试有线协议(Java 远程调试底层通信协议)
remote JVM:远程 Java 虚拟机
step through code:代码单步调试(步入 / 步过 / 步出调试)
inspect variables:变量查看 / 变量检视
stac</p>
</div>
<a rel="nofollow" href="/xiazai/skill11083" title="Java调试" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
<p>需求描述:<span>${requirementDescription}</span></p>
<hr>
</iterator>
<!-- 分页 -->
<p>
<nav>
<ul>
<!-- 判断当前页是否位1,如果不为1则显示上一页, -->
<if>
</if>
<else>
<li>
<a>
<span>«</span>
</a>
</li>
</else>
<!-- 首页 -->
<li><a>首页</a></li>
<li>
<span><span>${currentPage}</span>/ ${allPage}页</span>
</li>
<!-- 尾页 -->
<li><a>尾页</a></li>
<!-- 判断当前页和总页数,小于则显示下一页, -->
<if>
<li>
<a>
<span>»</span>
</a>
</li>
</if>
<li>
<span>跳转到第
<select>
<iterator>
<if>
<option></option>" ><property></property>
</if>
<else>
<option></option>" ><property></property>
</else>
</iterator>
</select>
页
</span>
</li>
</ul>
</nav>
</p>
<hr>
action
//查询需求列表
public String queryRequirListByPage(){
int pageSize=5;//每页记录
String hql="select r from Requirement r where r.reStatus !=2 ";
if(sortValue == null || sortValue.length() requiList=requirementService.queryByPage(hql, pageNo, pageSize);
ActionContext.getContext().put("requiList", requiList);//需求列表
ActionContext.getContext().put("icount", icount);//总记录数
ActionContext.getContext().put("allPage", allPage);//总页数
ActionContext.getContext().put("currentPage", pageNo); //当前页码
session.put("sessionCurrentPage", pageNo);
return "requireContent";
}
service
public long countAllRe() {
return requirementDao.countAllRe();
}
public List<t> queryByPage(String hql, int pageNo, int pageSize) {
return requirementDao.queryByPage(hql, pageNo, pageSize);
}</t>
dao
//这里可能会报错,就是直接查询数据列表(使用了SSH)
public long countAll() {
List> l = getSession().createQuery("select count(*) from "
+ clazz.getSimpleName()).list();
if (l != null && l.size() == 1 )
{
return (Long)l.get(0);
}
return 0;
}
public List<t> queryByPage(String hql, int pageNo, int pageSize) {
return getSession()
.createQuery(hql)
.setFirstResult((pageNo - 1) * pageSize)
.setMaxResults(pageSize)
.list();
}</t>
Java免费学习笔记:立即使用
解锁 Java 大师之旅:从入门到精通的终极指南










