🚀 feat(新增): 手写SQL分页查询完成

This commit is contained in:
Bunny 2024-09-12 23:56:19 +08:00
parent ce8c83b7a8
commit 02e14e60da
4 changed files with 18 additions and 4 deletions

View File

@ -2,7 +2,19 @@
<project version="4"> <project version="4">
<component name="GitCommitMessageStorage"> <component name="GitCommitMessageStorage">
<option name="messageStorage"> <option name="messageStorage">
<MessageStorage /> <MessageStorage>
<option name="commitTemplate">
<CommitTemplate>
<option name="body" value="" />
<option name="changes" value="" />
<option name="closes" value="" />
<option name="scope" value="" />
<option name="skipCi" value="" />
<option name="subject" value="" />
<option name="type" value="feat" />
</CommitTemplate>
</option>
</MessageStorage>
</option> </option>
</component> </component>
</project> </project>

View File

@ -12,11 +12,11 @@ public static class GetPagedResultAsync
return new PageResult<T>(page, limit, total, items); return new PageResult<T>(page, limit, total, items);
} }
public static async Task<PageResult<T>> GetPagedListFromSqlAsync<T>(DbContext dbContext, string sql, string table, int page, int limit) public static async Task<PageResult<T>> GetPagedListFromSqlAsync<T>(DbContext dbContext, string sql, int page, int limit)
where T : class where T : class
{ {
// 计算SQL查询的总数 // 计算SQL查询的总数
var total = await dbContext.Set<T>().CountAsync(); var total = dbContext.Set<T>().Count();
// 执行分页查询 // 执行分页查询
var paginatedSql = var paginatedSql =

View File

@ -24,4 +24,6 @@ public class BaseEntity
[Comment("并发版本")] [Comment("并发版本")]
[Column(TypeName = "datetime")] [Column(TypeName = "datetime")]
public DateTime Version { get; set; } public DateTime Version { get; set; }
// [NotMapped] public int Total { get; set; }
} }

View File

@ -119,7 +119,7 @@ public class UserService : IUserService
/// <param name="limit"></param> /// <param name="limit"></param>
public Task<PageResult<Users>> QueryPage(int page, int limit) public Task<PageResult<Users>> QueryPage(int page, int limit)
{ {
var pagedListAsync = GetPagedResultAsync.GetPagedListFromSqlAsync<Users>(DbContext, "select * from System_Users ", "System_Users", page, limit); var pagedListAsync = GetPagedResultAsync.GetPagedListFromSqlAsync<Users>(DbContext, "select * from System_Users ", page, limit);
return pagedListAsync; return pagedListAsync;
} }
} }