1111
This commit is contained in:
27
Service/Application.Service.Pub/Extends/PageExtend.cs
Normal file
27
Service/Application.Service.Pub/Extends/PageExtend.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace Application.Service.Pub;
|
||||
|
||||
public class PageExtend
|
||||
{
|
||||
/// <summary>
|
||||
/// List 通用分页
|
||||
/// </summary>
|
||||
/// <param name="list">数据源</param>
|
||||
/// <param name="pageIndex">当前页码(从1开始)</param>
|
||||
/// <param name="pageSize">每页条数</param>
|
||||
/// <returns>当前页数据</returns>
|
||||
public static List<T> GetPageList<T>(List<T> list, int pageIndex, int pageSize)
|
||||
{
|
||||
// 空值保护
|
||||
if (list == null || list.Count == 0)
|
||||
return new List<T>();
|
||||
|
||||
// 页码最小为 1
|
||||
pageIndex = pageIndex < 1 ? 1 : pageIndex;
|
||||
|
||||
// 分页核心
|
||||
return list
|
||||
.Skip((pageIndex - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user