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