当前位置: 技术问答>java相关
大家对在jsp里面分页显示有什么好的建议?
来源: 互联网 发布时间:2015-02-08
本文导语: 我是写了个类,通过Vector来传递 而需要分页的Vector我是放在session里面的,有没有必要放在session呢? 这样对性能有帮助吗? | 用xml结合javabean来实现.如果需要,我给你一个例子. ...
我是写了个类,通过Vector来传递
而需要分页的Vector我是放在session里面的,有没有必要放在session呢?
这样对性能有帮助吗?
而需要分页的Vector我是放在session里面的,有没有必要放在session呢?
这样对性能有帮助吗?
|
用xml结合javabean来实现.如果需要,我给你一个例子.
|
通过存储过程。
每次只取一页的数据。
示例如下(有点小问题,是倒序的)
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_GetauthorPage]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SP_GetauthorPage]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE SP_GetauthorPage(
@CurrentPage int,
@PageSize int
) AS
declare @sSQL1 varchar(500)
declare @sSQL2 varchar(500)
declare @iCount int
declare @PageCount int
declare @RecordCount int
set @iCount=@CurrentPage*@PageSize
print @iCount
select @RecordCount=Count(*) from author
print @RecordCount
if @RecordCount >0
begin
if @RecordCount % @PageSize=0
begin
set @PageCount=@RecordCount/@PageSize
end
else
begin
set @PageCount=@RecordCount/@PageSize+1
end
if @CurrentPage0
begin
set @sSQL1='(select top '+ ltrim(rtrim(str(@iCount))) +' * from author order by au_lname ) as tmp'
--print @sSQL1
set @sSQL2='select top ' +ltrim(rtrim(str(@PageSize)))+' * from '+@sSQL1 +' order by au_lname desc '
print @sSQL2
EXEC(@sSQL2)
end
else
begin
select top 0 * from author
end
end
else
begin
select * from author
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
每次只取一页的数据。
示例如下(有点小问题,是倒序的)
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SP_GetauthorPage]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[SP_GetauthorPage]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE SP_GetauthorPage(
@CurrentPage int,
@PageSize int
) AS
declare @sSQL1 varchar(500)
declare @sSQL2 varchar(500)
declare @iCount int
declare @PageCount int
declare @RecordCount int
set @iCount=@CurrentPage*@PageSize
print @iCount
select @RecordCount=Count(*) from author
print @RecordCount
if @RecordCount >0
begin
if @RecordCount % @PageSize=0
begin
set @PageCount=@RecordCount/@PageSize
end
else
begin
set @PageCount=@RecordCount/@PageSize+1
end
if @CurrentPage0
begin
set @sSQL1='(select top '+ ltrim(rtrim(str(@iCount))) +' * from author order by au_lname ) as tmp'
--print @sSQL1
set @sSQL2='select top ' +ltrim(rtrim(str(@PageSize)))+' * from '+@sSQL1 +' order by au_lname desc '
print @sSQL2
EXEC(@sSQL2)
end
else
begin
select top 0 * from author
end
end
else
begin
select * from author
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO