分页非为前端分页 和 后端分页,前端分页只有适用于B/S,B/S的呈现速度远远不如C/S,而C/S则没有这个问题,所以分页必然是后端分页
这里先要说明WinForm分页和Web分页都会存在一个问题:查两次(一次取得页面总数,一次取得当前页数据)
所以分页是需要数据特别大的时候才具有优化的意义,比如查询100条数据是1ms 查询1000条数据是1.1s如果使用分页,那么查询的耗时基本上就是2ms(算上嵌套查询的话是3ms),so自行掂量
控件网上有很多不多说了
说下sql(EF的略过)
-------这就是多出的一次查询,为了取得总的页数DECLARE @Total INT SELECT @Total = COUNT(0) FROM Sys_Button A WHERE 1 = 1 AND A.IsDelete = 0 AND ISNULL(A.Button_Name,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Name,ISNULL(A.Button_Name,‘‘)) +‘%‘ AND ISNULL(A.Button_Nick,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Nick,ISNULL(A.Button_Nick,‘‘)) +‘%‘ AND ISNULL(A.Button_Hint,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Hint,ISNULL(A.Button_Hint,‘‘)) +‘%‘ AND ISNULL(A.Button_Sub,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Sub,ISNULL(A.Button_Sub,‘‘)) +‘%‘ SELECT B.* FROM( SELECT A.Button_Id ,A.Button_Name , ----这里就是重点实现分页的代码了 @Total PageRecord ,ROW_NUMBER() OVER (ORDER BY Page_Nick,A.Button_Sort ) Record_Id, (@Total / @PageSize) + 1 PageCount FROM Sys_Button A LEFT JOIN Sys_Page B ON A.Button_Page = B.Page_Id WHERE 1 = 1 AND A.IsDelete = 0 AND ISNULL(A.Button_Name,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Name,ISNULL(A.Button_Name,‘‘)) +‘%‘ AND ISNULL(A.Button_Nick,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Nick,ISNULL(A.Button_Nick,‘‘)) +‘%‘ AND ISNULL(A.Button_Hint,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Hint,ISNULL(A.Button_Hint,‘‘)) +‘%‘ AND ISNULL(A.Button_Sub,‘‘) LIKE ‘%‘+ ISNULL(@cButton_Sub,ISNULL(A.Button_Sub,‘‘)) +‘%‘ ) B WHERE B.Record_Id > (@PageIndex - 1) * @PageSize AND B.Record_Id <= (@PageIndex) * @PageSize ORDER BY Page_Nick, Button_Sort
时间: 2024-10-30 07:54:41