zoukankan      html  css  js  c++  java
  • 通用分页请求返回类

    using System.Runtime.Serialization;
    
        /// <summary>
        /// 通用分页请求类
        /// </summary>
        [DataContract]
        public class PagedListModelReq : Request
        {
            /// <summary>
            /// <strong>Initializes a new instance of the <see cref="</strong>OperationLogReq<strong>" /> class</strong>
            /// OperationLogReq
            /// </summary>
            public PagedListModelReq()
            {
                this.PageIndex = 1;
                this.PageSize = 15;
            }
    
            /// <summary>
            /// 索引开始
            /// </summary>
            [DataMember]
            public int StartIndex
            {
                get
                {
                    int index = 0;
                    if (this.PageSize > 0 && this.PageIndex > 0)
                    {
                        index = ((this.PageIndex - 1) * this.PageSize) + 1;
                    }
    
                    return index;
                }
            }
    
            /// <summary>
            /// 索引结束
            /// </summary>
            [DataMember]
            public int EndIndex
            {
                get
                {
                    int index = 1;
                    if (this.PageSize > 0 && this.PageIndex > 0)
                    {
                        index = this.PageIndex * this.PageSize;
                    }
    
                    return index;
                }
            }
    
            /// <summary>
            /// 分页大小
            /// </summary>
            [DataMember]
            public int PageSize { get; set; }
    
            /// <summary>
            /// 第几页数
            /// </summary>
            [DataMember]
            public int PageIndex { get; set; }
    
            /// <summary>
            /// Called when [deserialized].
            /// </summary>
            /// <param name="context">StreamingContext</param>
            [OnDeserialized]
            private void OnDeserialized(StreamingContext context)
            {
                if (this.PageIndex <= 0)
                {
                    this.PageIndex = 1;
                }
    
                if (this.PageSize <= 0)
                {
                    this.PageSize = 15;
                }
            }
        }
    
        /// <summary>
        /// 通用分页请求类
        /// </summary>
        /// <typeparam name="T">Poco类型</typeparam>
        [DataContract]
        public class PagedListModelReq<T> : Request
        {
            /// <summary>
            /// <strong>Initializes a new instance of the <see cref="</strong>OperationLogReq<strong>" /> class</strong>
            /// OperationLogReq
            /// </summary>
            public PagedListModelReq()
            {
                this.PageIndex = 1;
                this.PageSize = 15;
            }
    
            /// <summary>
            /// 索引开始
            /// </summary>
            [DataMember]
            public int StartIndex
            {
                get
                {
                    int index = 0;
                    if (this.PageSize > 0 && this.PageIndex > 0)
                    {
                        index = ((this.PageIndex - 1) * this.PageSize) + 1;
                    }
    
                    return index;
                }
            }
    
            /// <summary>
            /// 索引结束
            /// </summary>
            [DataMember]
            public int EndIndex
            {
                get
                {
                    int index = 1;
                    if (this.PageSize > 0 && this.PageIndex > 0)
                    {
                        index = this.PageIndex * this.PageSize;
                    }
    
                    return index;
                }
            }
    
            /// <summary>
            /// 分页大小
            /// </summary>
            [DataMember]
            public int PageSize { get; set; }
    
            /// <summary>
            /// 第几页数
            /// </summary>
            [DataMember]
            public int PageIndex { get; set; }
    
            /// <summary>
            /// Called when [deserialized].
            /// </summary>
            /// <param name="context">序列化的上下文</param>
            [OnDeserialized]
            private void OnDeserialized(StreamingContext context)
            {
                if (this.PageIndex <= 0)
                {
                    this.PageIndex = 1;
                }
    
                if (this.PageSize <= 0)
                {
                    this.PageSize = 15;
                }
            }
        }
        [Serializable]
        [DataContract]
        public class PagedResult<T> : IPagedResult<T>
        {
            protected PagedResult();
            public PagedResult(IList<T> source, int pageIndex, int pageSize);
            public PagedResult(IQueryable<T> source, int pageIndex, int pageSize);
            public PagedResult(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount);
    
            [DataMember]
            public bool HasNextPage { get; }
            [DataMember]
            public bool HasPreviousPage { get; }
            [DataMember]
            public IEnumerable<T> Items { get; }
            [DataMember]
            public int PageIndex { get; }
            [DataMember]
            public int PageSize { get; }
            [DataMember]
            public int TotalCount { get; }
            [DataMember]
            public int TotalPages { get; }
        }
    /// <summary>
        /// 通用分页返回类
        /// </summary>
        /// <typeparam name="T">Model对应的类型</typeparam>
        [DataContract]
        public class PagedListModelResp<T> : Response
        {
            /// <summary>
            /// 返回分页数据
            /// </summary>
            [DataMember]
            public PagedResult<T> List { get; set; }
        }
  • 相关阅读:
    Jenkins分享
    Java静态绑定和动态绑定
    SpringBoot中RedisTemplate订阅发布对象
    Idea项目:Failed to create a Maven project ‘…pom.xml’ already exists in VFS 解决
    Java Web不能不懂的知识
    Required String parameter 'id' is not present
    Hive使用druid做连接池代码实现
    Docker Toolbox常见错误解决方案
    初学者手册-MyBatis踩坑记(org.apache.ibatis.binding.BindingException)
    SpringMVC日志管理(自定义异常及自定义注解)
  • 原文地址:https://www.cnblogs.com/zhshlimi/p/9072918.html
Copyright © 2011-2022 走看看