1. 前端一下獲取所有數據怎麼實現分頁
grid的分頁功能本身就是對資料庫數據分頁後的一個數據顯示,並可以執行翻頁查詢其他頁的信息。全部信息則只需要將limit參數設置為數據總條數,pagesize也設置為數據行數。grid中不設置分頁組件是可以直接顯示全部信息,url中不設置limit和start參數。注:數據量太多時不宜全部顯示
2. java的jsp如何分頁顯示查詢結果呢
//分頁類
publicclassPager{
privateintpageNow=1;//
privateintpageSize=7;//
privateinttotalPage;//
privateinttotalSize;//
publicPager(intpageNow,inttotalSize){
this.pageNow=pageNow;
this.totalSize=totalSize;
}
publicintgetPageNow(){
returnpageNow;
}
publicvoidsetPageNow(intpageNow){
this.pageNow=pageNow;
}
publicintgetPageSize(){
returnpageSize;
}
publicvoidsetPageSize(intpageSize){
this.pageSize=pageSize;
}
publicintgetTotalPage(){
totalPage=getTotalSize()/getPageSize();
if(totalSize%pageSize!=0)
totalPage++;
returntotalPage;
}
publicvoidsetTotalPage(inttotalPage){
this.totalPage=totalPage;
}
publicintgetTotalSize(){
returntotalSize;
}
publicvoidsetTotalSize(inttotalSize){
this.totalSize=totalSize;
}
publicbooleanisHasFirst(){
if(pageNow==1)
returnfalse;
else
returntrue;
}
publicvoidsetHasFirst(booleanhasFirst){
}
publicbooleanisHasPre(){
if(this.isHasFirst())
returntrue;
else
returnfalse;
}
publicvoidsetHasPre(booleanhasPre){
}
publicbooleanisHasNext(){
if(isHasLast())
returntrue;
else
returnfalse;
}
publicvoidsetHasNext(booleanhasNext){
}
publicbooleanisHasLast(){
if(pageNow==this.getTotalPage())
returnfalse;
else
returntrue;
}
publicvoidsetHasLast(booleanhasLast){
}
}
//service層
publicclassPageService{
@SuppressWarnings("unchecked")
publicList<?>list(intpageNow,intpageSize,Stringhql){
Sessionsession=HibernateSessionFactory.getSession();
Transactiontx=session.beginTransaction();
List<Object>objects;
Queryquery=session.createQuery(hql);
query.setFirstResult(pageSize*(pageNow-1));
query.setMaxResults(pageSize);
objects=query.list();
tx.commit();
returnobjects;
}
}
//在action中調用
publicStringlistUser(){
Stringhql="fromUserinfou";
if(ps.list(pageNow,pageSize,hql)!=null){
userinfos=(List<Userinfo>)ps.list(pageNow,pageSize,hql);
Map<String,Object>request=(Map<String,Object>)ActionContext
.getContext().get("request");
Pagerpage=newPager(this.getPageNow(),us.getUserSize());
request.put("userinfos",userinfos);
request.put("page",page);
returnAction.SUCCESS;
}else{
returnAction.LOGIN;
}
}
//jsp中
<body>
<tablewidth="832"border="0"cellpadding="0"cellspacing="0"id="listBook">
<trbgcolor="#E7E7E9">
<tdwidth="5%"height="40"> </td>
<tdwidth="25%"colspan="2"bgcolor="#E7E7E9"><divalign="center"class="STYLE10">郵箱</div></td>
<tdwidth="25%"colspan="2"bgcolor="#E7E7E9"class="STYLE1"><divalign="center"class="STYLE10">密碼</div></td>
<tdwidth="25%"colspan="2"bgcolor="#E7E7E9"class="STYLE1"><divalign="center"class="STYLE10">許可權</div></td>
<tdwidth="8%"bgcolor="#E7E7E9"><spanclass="STYLE8"></span></td>
<tdwidth="8%"bgcolor="#E7E7E9"><spanclass="STYLE8"></span></td>
</tr>
<s:iteratorvalue="#request.userinfos"id="oneUser">
<tr>
<tdheight="50">
<divalign="center">
<inputtype="checkbox"name="checkbox"value="checkbox"/>
</div></td>
<tdwidth="5%"></td>
<tdwidth="23%"class="STYLE4"><s:property
value="#oneUser.email"/></td>
<tdwidth="5%"class="STYLE4"></td>
<tdwidth="23%"><spanclass="STYLE4"><s:property
value="#oneUser.password"/></span></td>
<tdwidth="5%"class="STYLE4"></td>
<tdwidth="23%"><spanclass="STYLE4">
<s:iftest="#oneUser.power==1">
普通用戶
</s:if>
<s:else>
管理員
</s:else>
</span></td>
<td><divalign="right"class="STYLE1"><ahref='deleteUser?userid=<s:propertyvalue="#oneUser.id"/>'class="STYLE5">刪除|</a></div></td>
<tdclass="STYLE1"><ahref='lookUser?userid=<s:propertyvalue="#oneUser.id"/>&pageNow=<s:propertyvalue="#request.page.pageNow"/>'target="_self"class="STYLE5">修改</a></td>
</tr>
</s:iterator>
<tr>
<tdcolspan="9"><tablewidth="832"border="0"cellspacing="0"bgcolor="#E7E7E9">
<s:setname="page"value="#request.page"></s:set>
<tr>
<tdwidth="70%"> </td>
<s:iftest="#page.isHasPre()">
<tdwidth="10%"><ahref='listUser?pageNow=<s:propertyvalue="#page.pageNow-1"/>'target="_self"class="STYLE3">上一頁</a></td>
</s:if>
<s:else>
<tdwidth="10%"><ahref="listUser?pageNow=1"target="_self"class="STYLE3">上一頁</a></td>
</s:else>
<s:iftest="#page.isHasNext()">
<tdwidth="10%"><ahref="listUser?pageNow=<s:propertyvalue="#page.pageNow+1"/>"target="_self"class="STYLE3">下一頁</a></td>
</s:if>
<s:else>
<tdwidth="10%"><ahref="listUser?pageNow=<s:propertyvalue="#page.totalPage"/>"target="_self"class="STYLE3">下一頁</a></td>
</s:else>
<tdwidth="10%"><ahref="listUser?pageNow=<s:propertyvalue="#page.totalPage"/>"target="_self"class="STYLE3">尾頁</a></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
這是採用struts2+hibernate 做的,你可以參考一下
3. jsp中如何分頁顯示查詢到的數據
jsp中分頁顯示查詢到的數據是通過foreach標簽控制的,一般是顯示首頁,下一頁,上一頁,尾頁這些連接項。
1、構建一個PageControl對象將分頁所涉及到的一些關鍵的"控制數據"予以封裝.
4. 分頁查詢的sql 語句(參數1,參數2)怎麼寫
你說的應該是 利用SQL的游標存儲過程 來分頁的形式
代碼如下:
create procere fenye
@sqlstr nvarchar(4000), --查詢字元串
@currentpage int, --第N頁
@pagesize int --每頁行數
as
set nocount on
declare @P1 int, --P1是游標的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select ceiling(1.0*@rowcount/@pagesize) as 總頁數--,@rowcount as 總行數,@currentpage as 當前頁
set @currentpage=(@currentpage-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@currentpage,@pagesize
exec sp_cursorclose @P1
set nocount off
不過這個種存儲過程分頁的方法效率比較差
建議你直接用代碼進行分頁
或者 利用SELECT TOP分頁
代碼:
select top 10 * from [order details]
where orderid>all(select top 10 orderid from [order details] order by orderid)
order by orderid