mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
🚀增加分页模型分页及示例
This commit is contained in:
@ -63,6 +63,17 @@ namespace restful.Controllers
|
||||
return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
|
||||
/// </summary>
|
||||
/// <param name="pagingInfo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetPagingItems")]
|
||||
public Task<List<Song>> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
|
||||
{
|
||||
return _songRepository.Select.WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public Task<Song> GetItem([FromRoute] int id)
|
||||
{
|
||||
|
57
Examples/repository_01/PagingInfo.cs
Normal file
57
Examples/repository_01/PagingInfo.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace repository_01
|
||||
{
|
||||
public class PagingInfo : BasePagingInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 无参构造函数
|
||||
/// </summary>
|
||||
public PagingInfo()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前为第1页,每页大小的构造函数
|
||||
/// </summary>
|
||||
/// <param name="pageSize"></param>
|
||||
public PagingInfo(int pageSize)
|
||||
{
|
||||
PageNumber = 1;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
/// <summary>
|
||||
/// 带当前页和每页大小的构造函数
|
||||
/// </summary>
|
||||
/// <param name="pageNumber"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
public PagingInfo(int pageNumber, int pageSize)
|
||||
{
|
||||
PageNumber = pageNumber;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前有多少页【只读】
|
||||
/// </summary>
|
||||
public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
|
||||
/// <summary>
|
||||
/// 是否有上一页【只读】
|
||||
/// </summary>
|
||||
public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
|
||||
/// <summary>
|
||||
/// 是否有下一页【只读】
|
||||
/// </summary>
|
||||
public bool HasNext => PageNumber < PageCount;
|
||||
/// <summary>
|
||||
/// 是否在第一页【只读】
|
||||
/// </summary>
|
||||
public bool IsFrist => PageNumber == 1;
|
||||
/// <summary>
|
||||
/// 是否在最后一页【只读】
|
||||
/// </summary>
|
||||
public bool IsLast => PageNumber == PageCount;
|
||||
}
|
||||
}
|
@ -25,6 +25,18 @@ namespace restful.Controllers
|
||||
return _fsql.Select<Song>().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(page, limit).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// curl -X GET "http://localhost:5000/restapi/Songs/GetPagingItems?key=FreeSql&PageNumber=2&PageSize=10" -H "accept: text/plain"
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="pagingInfo"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("GetPagingItems")]
|
||||
public Task<List<Song>> GetPagingItems([FromQuery] string key, [FromQuery] PagingInfo pagingInfo)
|
||||
{
|
||||
return _fsql.Select<Song>().WhereIf(!string.IsNullOrEmpty(key), a => a.Title.Contains(key)).Page(pagingInfo).ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public Task<Song> GetItem([FromRoute] int id)
|
||||
{
|
||||
|
57
Examples/restful/PagingInfo.cs
Normal file
57
Examples/restful/PagingInfo.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using FreeSql.Internal.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace restful
|
||||
{
|
||||
public class PagingInfo : BasePagingInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 无参构造函数
|
||||
/// </summary>
|
||||
public PagingInfo()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前为第1页,每页大小的构造函数
|
||||
/// </summary>
|
||||
/// <param name="pageSize"></param>
|
||||
public PagingInfo(int pageSize)
|
||||
{
|
||||
PageNumber = 1;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
/// <summary>
|
||||
/// 带当前页和每页大小的构造函数
|
||||
/// </summary>
|
||||
/// <param name="pageNumber"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
public PagingInfo(int pageNumber, int pageSize)
|
||||
{
|
||||
PageNumber = pageNumber;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
/// <summary>
|
||||
/// 当前有多少页【只读】
|
||||
/// </summary>
|
||||
public long PageCount => PageSize == 0 ? 0 : (Count + PageSize - 1) / PageSize;
|
||||
/// <summary>
|
||||
/// 是否有上一页【只读】
|
||||
/// </summary>
|
||||
public bool HasPrevious => PageNumber > 1 && PageNumber <= PageCount;
|
||||
/// <summary>
|
||||
/// 是否有下一页【只读】
|
||||
/// </summary>
|
||||
public bool HasNext => PageNumber < PageCount;
|
||||
/// <summary>
|
||||
/// 是否在第一页【只读】
|
||||
/// </summary>
|
||||
public bool IsFrist => PageNumber == 1;
|
||||
/// <summary>
|
||||
/// 是否在最后一页【只读】
|
||||
/// </summary>
|
||||
public bool IsLast => PageNumber == PageCount;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user