zoukankan      html  css  js  c++  java
  • MVC中对controller的抽象

    将所有controller的公共属性和方法提取出来,放到一个controller基类里,共其它controller使用,这无疑不是一个好的选择,以下是我的项目中controller层的抽象,分享一下代码:

    /// <summary>
        /// Controller基类
        /// </summary>
        public abstract class ControllerBase : Controller
        {

            #region Fields

            #endregion

            #region Constructor

            #endregion

            #region Properties
            /// <summary>
            /// 通用信息(一般由service层返回的)
            /// </summary>
            protected Entity.VMessage VMessage { get; set; }
            #endregion

            #region Protected Consts
            /// <summary>
            /// 每页显示的记录数
            /// </summary>
            protected const int PAGESIZE = 10;
            #endregion

            #region Protected virtual Properties
            /// <summary>
            /// 查询器属性
            /// </summary>
            protected virtual Entity.VPredication vp { get; set; }
            /// <summary>
            /// 分页结构属性
            /// </summary>
            protected virtual Entity.PagingParam pp { get; set; }
            #endregion

            #region Protected virtual Methods
            /// <summary>
            /// 操作后,显示的提示成功或失败的信息
            /// author:zzl
            /// </summary>
            /// <param name="msg">提示信息,操作成功或操作失败</param>
            /// <param name="url">点击返回列表后,所进入的地址</param>
            /// <returns></returns>
            protected virtual string DisplayMsg(string msg, string url)
            {
                string message = string.Format("<div style='color:red;font-size:14px;background:rgb(244,250,251);border:rgb(187,221,229) 1px solid;margin:3px;padding:3px'>{0},<a href='{1}'>返回列表</a></div>", msg, url);
                return message;
            }
            protected virtual string DisplayMsg(string msg)
            {
                string message = string.Format("<div style='color:red;font-size:14px;background:rgb(244,250,251);border:rgb(187,221,229) 1px solid;margin:3px;padding:3px'>{0}</div>", msg);
                return message;
            }
            #endregion

       #endregion

        }

  • 相关阅读:
    安装git工具在ubuntu系统
    Ubuntu 16.04安装JDK并配置环境变量-【小白版】
    【gRPC使用问题4】
    【gRPC使用问题3】生成出来无法识别Google.Api.AnnotationsReflection.Descriptor
    LNMP
    Centos下安装Mysql
    yum方式安装的Apache目录详解和配置说明
    Centos下 yum方式安装LAMP
    CentOS配置网易163 yum源
    Apache主配置文件httpd.conf 详解
  • 原文地址:https://www.cnblogs.com/lori/p/2275160.html
Copyright © 2011-2022 走看看