using Cloudcubic.Common; namespace CloudCubic.Model.DTO.Base { /// <summary> /// 2023-04-23 新增 /// </summary> /// <typeparam name="T"></typeparam> public class ApiResult<T> : ApiResultBase { /// <summary> /// 返回数据 /// </summary> public T data { get; set; } // public List<T> rows { get; set; } /// <summary> /// 返回数据 成功 /// </summary> /// <param name="data">数据</param> /// <param name="state">状态 200成功,500失败</param> /// <param name="success">默认true</param> /// <param name="msg">消息</param> /// <returns></returns> public static ApiResult<T> SuccessApiResult(T data = default, int state = 200, bool success = true, string msg = ApiMsgEnum.OPRATIONSUCCESS) { return new ApiResult<T>() { msg = msg, status = state, success = success, data = data }; } /// <summary> /// 返回数据 失败 /// </summary> /// <param name="data">数据</param> /// <param name="state">状态 200成功,500失败</param> /// <param name="success">默认false</param> /// <param name="msg">消息</param> /// <returns></returns> public static ApiResult<T> FailApiResult(T data = default, int state = 500, bool success = false, string msg = ApiMsgEnum.OPRATIONFAIL) { return new ApiResult<T>() { msg = msg, status = state, success = success, data = data }; } } }
using Cloudcubic.Common; using System.Collections.Generic; namespace CloudCubic.Model { /// <summary> /// 2023-03-23 新增 /// </summary> public class ApiResultBase { /// <summary> /// 状态码 /// </summary> public int status { get; set; } /// <summary> /// 是否成功 /// </summary> public bool success { get; set; } /// <summary> /// 返回的消息 /// </summary> public string msg { get; set; } } public class ApiResultPage<T>: ApiResultBase { /// <summary> /// 当前页标 /// </summary> public int pageIndex { get; set; } /// <summary> /// 每页大小 /// </summary> public int pageSize { set; get; } /// <summary> /// 数据总数 /// </summary> public int dataCount { get; set; } /// <summary> /// 总页数 /// </summary> public int pageCount { get; set; } /// <summary> /// 返回数据 /// </summary> public T data { get; set; } /// <summary> /// 分页接口格式 返回成功 /// </summary> /// <param name="data"></param> /// <param name="pageIndex">第几页</param> /// <param name="pageSize">一页大小</param> /// <param name="dataCount">总数量</param> /// <param name="state">状态码</param> /// <param name="success">true,false</param> /// <param name="msg"></param> /// <returns></returns> public static ApiResultPage<T> SuccessApiResultPage(T data=default, int dataCount=0, int pageIndex = 1, int pageSize = 10, int state = 200, bool success = true, string msg = ApiMsgEnum.QUERYSUCCESS) { pageIndex = pageIndex <= 0 ? 1 : pageIndex; pageSize = pageSize <= 0 ? 1 : pageSize; return new ApiResultPage<T>() { msg = msg, status = state, success = success, pageIndex = pageIndex, dataCount = dataCount, pageSize = pageSize, pageCount = dataCount % pageSize > 0 ? (dataCount / pageSize) + 1 : dataCount / pageSize, data = data }; } /// <summary> /// 分页接口格式 返回失败 /// </summary> /// <param name="data"></param> /// <param name="pageIndex">第几页</param> /// <param name="pageSize">一页大小</param> /// <param name="dataCount">总数据数量</param> /// <param name="state">状态码</param> /// <param name="success">true,false</param> /// <param name="msg"></param> /// <returns></returns> public static ApiResultPage<T> FailApiResultPage(T data= default, int dataCount=0, int pageIndex = 1, int pageSize = 10, int state = 500, bool success = false, string msg = ApiMsgEnum.OPRATIONFAIL) { pageIndex = pageIndex <= 0 ? 1 : pageIndex; pageSize = pageSize <= 0 ? 1 : pageSize; return new ApiResultPage<T>() { msg = msg, status = state, success = success, pageIndex = pageIndex, pageSize = pageSize, dataCount = dataCount, pageCount = dataCount % pageSize > 0 ? (dataCount / pageSize) + 1 : dataCount / pageSize, data = data }; } } }
标签:Dto,pageSize,int,dataCount,api,msg,格式,data,public From: https://www.cnblogs.com/Fengge518/p/17430163.html