服务端的分页就一个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)

该段语句主要是将表 appemployee 赋值一个ID,便于分页的处理,同时是按照名称的英文名进行排序!


分析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中利用分页的请求方式(客户端分页后续讨论),即可对接到服务端。