今天就跟大家聊聊有關(guān)利用Java如何實(shí)現(xiàn)前臺(tái)與后臺(tái)頁(yè)面分頁(yè),可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到青山網(wǎng)站設(shè)計(jì)與青山網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站建設(shè)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋青山地區(qū)。
先上圖吧,大致如圖,也就提供個(gè)思路(ps:使用了SSH框架)

前臺(tái)JSP頁(yè)面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>數(shù)據(jù)交易貓</title>
<script type="text/javascript">
//1分頁(yè)下,動(dòng)態(tài)添加disable給分頁(yè)按鈕
/*
$(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(){
})
//根據(jù)頁(yè)數(shù)查詢數(shù)據(jù)列表
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){
$('#requireContentDiv').html(datas);
},
error:function(){
alert("失敗");
},
});
}
//根據(jù)下拉查詢數(shù)據(jù)列表
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){
$('#requireContentDiv').html(datas);
},
error:function(){
alert("失敗");
},
});
}
//根據(jù)下拉選擇排序方式
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){
$('#requireContentDiv').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>
</head>
<body>
<!-- 內(nèi)容-->
<div class="well">
<!-- 標(biāo)題-->
<div class="box"><h4><span class="glyphicon glyphicon-list" ></span>需求列表</h4></div>
<!-- 篩選條件-->
<div class="box">
<div class="row">
<div class="col-xs-12">
<span>篩選:按</span>
<select id="category" name="category" onchange="selectSort(this)">
<option id="categoryTime" value="publishDatetime">最新</option>
<option id="categoryPrice" value="price">價(jià)格降序</option>
<input id="backSortValue" type="hidden" value="${sortValue}">
</select>
<hr class="mrgZero mrgTopSma"/>
</div>
</div>
</div>
<!-- 內(nèi)容-->
<input type="hidden" name="hidCurrentPage2" id="hidCurrentPage" value="${currentPage}">
<input type="hidden" id="hidAllPage" value="${allPage}">
<input type="hidden" id="hidSortValue" value="${sortValue}">
<s:iterator value="#requiList">
<div class="data-down-box">
<div class="row">
<div class="col-xs-12">
<h5 class="ellipsis"><a href="${pageContext.request.contextPath}/bid/bidAction_queryById?id=${id}" rel="external nofollow" onclick="reward()">${title}</a></h5>
</div>
</div>
<div class="row mrgTopSma">
<div class="col-xs-12 ">
<p class="data-provider padLeftBig sec-color ellipsis">懸賞積分:<span>${price}</span></p>
<p class="data-intro padLeftBig ellipsis sec-color">需求描述:<span>${requirementDescription}</span></p>
</div>
</div>
<hr/>
</div>
</s:iterator>
<!-- 分頁(yè) -->
<div id="rePagerDiv" class="rePagerDiv box">
<nav>
<ul class="pager">
<!-- 判斷當(dāng)前頁(yè)是否位1,如果不為1則顯示上一頁(yè), -->
<s:if test="1 == #currentPage">
</s:if>
<s:else>
<li>
<a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Previous" onclick="queryRequirListByPage(${currentPage-1})">
<span aria-hidden="true">«</span>
</a>
</li>
</s:else>
<!-- 首頁(yè) -->
<li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="queryRequirListByPage(1)">首頁(yè)</a></li>
<li>
<span><span class="main-color">${currentPage}</span>/ ${allPage}頁(yè)</span>
</li>
<!-- 尾頁(yè) -->
<li><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="queryRequirListByPage(${allPage})">尾頁(yè)</a></li>
<!-- 判斷當(dāng)前頁(yè)和總頁(yè)數(shù),小于則顯示下一頁(yè), -->
<s:if test="#currentPage < #allPage">
<li>
<a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Next" onclick="queryRequirListByPage(${currentPage+1})">
<span aria-hidden="true">»</span>
</a>
</li>
</s:if>
<li>
<span class="skipPageSpan">跳轉(zhuǎn)到第
<select onchange="selectPage(this)">
<s:iterator var="lst" begin="1" end="#allPage" step="1">
<s:if test="%{#lst == #currentPage}">
<option selected="selected" value="<s:property/>" ><s:property/></option>
</s:if>
<s:else>
<option value="<s:property/>" ><s:property/></option>
</s:else>
</s:iterator>
</select>
頁(yè)
</span>
</li>
</ul>
</nav>
</div>
</div>
<hr/>
</body>
</html>action
//查詢需求列表
public String queryRequirListByPage(){
int pageSize=5;//每頁(yè)記錄
String hql="select r from Requirement r where r.reStatus !=2 ";
if(sortValue == null || sortValue.length() <= 0){
hql=hql+"order by r.publishDatetime desc";
ActionContext.getContext().put("sortValue", "publishDatetime"); //當(dāng)前頁(yè)碼條件
session.put("sessionReqSortValue","publishDatetime");
}else{
hql=hql+"order by r."+sortValue+" desc";
ActionContext.getContext().put("sortValue", sortValue); //當(dāng)前頁(yè)碼條件
session.put("sessionReqSortValue",sortValue);
}
long icount=requirementService.countAllRe();//總記錄數(shù)
long allPage;//總頁(yè)數(shù)
//判斷是否能整除,能則直接,不能則+1;
if((icount%pageSize)==0){
allPage=icount/pageSize;
}
else{
allPage=(icount/pageSize)+1;
}
System.out.println("總記錄:"+icount+";總頁(yè)數(shù):"+allPage+";當(dāng)前頁(yè)碼:"+pageNo);
List<Requirement> requiList=requirementService.queryByPage(hql, pageNo, pageSize);
ActionContext.getContext().put("requiList", requiList);//需求列表
ActionContext.getContext().put("icount", icount);//總記錄數(shù)
ActionContext.getContext().put("allPage", allPage);//總頁(yè)數(shù)
ActionContext.getContext().put("currentPage", pageNo); //當(dāng)前頁(yè)碼
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);
}dao
//這里可能會(huì)報(bào)錯(cuò),就是直接查詢數(shù)據(jù)列表(使用了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();
}看完上述內(nèi)容,你們對(duì)利用Java如何實(shí)現(xiàn)前臺(tái)與后臺(tái)頁(yè)面分頁(yè)有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
當(dāng)前文章:利用Java如何實(shí)現(xiàn)前臺(tái)與后臺(tái)頁(yè)面分頁(yè)
本文鏈接:http://chinadenli.net/article14/iigige.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、虛擬主機(jī)、面包屑導(dǎo)航、定制開(kāi)發(fā)、品牌網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)