• 获取Model的所有属性字符串


       /// <summary>
            /// 返回属性字段,作用是Sql查询的时候用来替换 * , *查询会影响运行速度
           /// </summary>
           /// <typeparam name="T"></typeparam>
           /// <returns></returns>
            public string GetModelSqlstr<T>()
            {
                string RtnStr = string.Empty;
                try
                {
    
                    Type entityType = typeof(T); 
                    System.Reflection.PropertyInfo[] properties = entityType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
    
                    foreach (PropertyInfo item in properties)
                    {
                        RtnStr = string.Format("{0},{1}", RtnStr, item.Name);
                    }
                    RtnStr = " "+RtnStr.TrimEnd(',').TrimStart(',')+" ";
                }
                catch (Exception)
                {
    
                    throw;
                }
    
                return RtnStr;
            }

       /// <summary>        /// 返回属性字段,作用是Sql查询的时候用来替换 * , *查询会影响运行速度       /// </summary>       /// <typeparam name="T"></typeparam>       /// <returns></returns>        public string GetModelSqlstr<T>()        {            string RtnStr = string.Empty;            try            {
                    Type entityType = typeof(T);                 System.Reflection.PropertyInfo[] properties = entityType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                    foreach (PropertyInfo item in properties)                {                    RtnStr = string.Format("{0},{1}", RtnStr, item.Name);                }                RtnStr = " "+RtnStr.TrimEnd(',').TrimStart(',')+" ";            }            catch (Exception)            {
                    throw;            }
                return RtnStr;        }

  • 相关阅读:
    VUE-路由配置及跳转方式
    VUE使用axios请求后端数据
    springboot图片/文件上传
    java中return;语句的作用
    使用maven搭建ssm框架环境
    Java和Tomcat安装教程
    安装tomcat出现的问题
    关于 == 和 equals() 的区别
    关于从request对象中获取路径的问题
    栈和队列_leetcode20
  • 原文地址:https://www.cnblogs.com/lhlong/p/11058627.html
Copyright © 2020-2023  润新知