服务端的分页就一个SQL语句就可以搞定,贴出代码后自己慢慢欣赏:
CREATE Procedure AppGetEmpList @EID int, @LGID int, @pagesize int, @pageindex int As Begin select count(*) count from appemployee
Select a.ID,a.EID,Case When @LGID=2052 Then Name Else eName End Name,DepTitle,JobTitle ,Case When b.xEID is null Then 0 Else 1 End Fav ,Case When Isnull(a.Reportto,0)=@EID Then 1 Else 0 End IsSub From (select row_number() over(order by left(a.ename,1)) ID ,a.* From appemployee a Where a.LGID=@LGID and Isnull(a.Status,0)<>4) a Left Join AppEmpFavorites b on a.EID=b.EID and b.xEID=@EID where a.ID between (@pageindex-1)*@pagesize+1 and @pageindex*@pagesize End |
分析1:
select row_number() over(order by left(a.ename,1)) ID ,a.* From appemployee a Where a.LGID=@LGID and Isnull(a.Status,0)<>4) |
分析2:
Select a.ID,a.EID,Case When @LGID=2052 Then Name Else eName End Name,DepTitle,JobTitle ,Case When b.xEID is null Then 0 Else 1 End Fav ,Case When Isnull(a.Reportto,0)=@EID Then 1 Else 0 End IsSub From (select row_number() over(order by left(a.ename,1)) ID ,a.* From appemployee a Where a.LGID=@LGID and Isnull(a.Status,0)<>4) a Left Join AppEmpFavorites b on a.EID=b.EID and b.xEID=@EID |
该段语句是在语句1的基础上通过EID进行过滤掉我们不需要的值
分析3:
where a.ID between (@pageindex-1)*@pagesize+1 and @pageindex*@pagesize |
该语句是通过传递的参数进行计算并取出指定的值返回给客户端。
综上,服务端只需要利用这个思路即可实现了分页的查询功能,然而android客户端在ListVIew中利用分页的请求方式(客户端分页后续讨论),即可对接到服务端。
本文出自 “吸博取精自我更新” 博客,请务必保留此出处http://wyong.blog.51cto.com/1115465/1618762
原文地址:http://wyong.blog.51cto.com/1115465/1618762