c# SQLHelper总汇

摘要:
//////SqlHelper分类旨在为SqlClient的常见用途提供高性能、可扩展的最佳实践///publicabstractclassSqlHelper{/////默认键//private
 /// <summary>
    ///The SqlHelper class is intended to encapsulate high performance, 
    ///scalable best practices for common uses of SqlClient.
    /// </summary>
    public abstract classSqlHelper
    {
        /// <summary>
        ///默认密匙
        /// </summary>
        private const string DefaultEncryptKey = "#4d&0)-.koOeG`~x";

        //Database connection strings
        private static string _SQLConnString = null;
        private ILog logger = LogManager.GetLogger("SQLHelper");
        public static stringSQLConnString
        {
            get{
                if (_SQLConnString == null)
                {
                    _SQLConnString = ConfigurationManager.ConnectionStrings["WFSQLConnString"].ConnectionString;
                    //_SQLConnString = IBOTech.Utility.Cryptography.TripledDESDecrypt(_SQLConnString, DefaultEncryptKey);
}

                return_SQLConnString;
            }
        }

        //Hashtable to store cached parameters
        private static Hashtable parmCache = Hashtable.Synchronized(newHashtable());

        /// <summary>
        ///生成分页SQL,仅适用于Sql Server 2005或以上版本
        /// </summary>
        /// <param name="startIndex">开始位置,从1开始</param>
        /// <param name="endIndex">结束位置</param>
        /// <param name="sql">必须以“select ”开头,以“ order by ...”结尾。</param>
        /// <returns></returns>
        public static string GetPagerSql(int startIndex, int endIndex, stringsql)
        {
            //去掉“select ”
            sql = sql.Remove(0, 7);

            //取order by
            int index = sql.ToLower().IndexOf("order by ");
            string orderby =sql.Substring(index);
            sql =sql.Remove(index);

            sql = "with temptbl as (SELECT ROW_NUMBER() OVER (" + orderby + ")AS Row, " + sql + ")";
            sql += "
SELECT * FROM temptbl where Row between " + startIndex.ToString() + "and " +endIndex.ToString();

             //ILog logger = LogManager.GetLogger("SQLHelper");
             //logger.Info("GetPagerSql:" + sql);
ICollection<string> Categories = new List<string>() { "3"};

            //System.Windows.Forms.MessageBox.Show(sql);
            Logger.Write("GetPagerSql:" + sql, Categories, 3, 0, TraceEventType.Error, "", "", "", "", "", null);
           //Logger.Write("test saitor");

            returnsql;
        }

        #region ExecuteDataset

        /// <summary>
        ///执行数据集
        /// </summary>
        /// <param name="transaction">事务</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="commandText">命令文本</param>
        /// <param name="commandParameters">参数</param>
        /// <returns></returns>
        public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, paramsSqlParameter[] commandParameters)
        {
            if (transaction == null) throw new ArgumentNullException("transaction");
            if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");

            //Create a command and prepare it for execution
            SqlCommand cmd = newSqlCommand();
            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);

            SqlDataAdapter da = newSqlDataAdapter(cmd);
            DataSet ds = newDataSet();
            da.Fill(ds);
            cmd.Parameters.Clear();
            da.Dispose();

            returnds;
        }

        /// <summary>
        ///执行数据集
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">sql语句</param>
        /// <param name="commandParameters">参数</param>
        /// <returns></returns>
        public static DataSet ExecuteDataset(string connectionString, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {
            SqlCommand cmd = newSqlCommand();
            SqlConnection conn = newSqlConnection(connectionString);

            try{
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);

                SqlDataAdapter da = newSqlDataAdapter(cmd);
                DataSet ds = newDataSet();
                da.Fill(ds);
                cmd.Parameters.Clear();
                da.Dispose();

                returnds;
            }
            catch{
                throw;
            }
            finally{
                conn.Close();
            }
        }

        /// <summary>
        ///执行数据集
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="SQLString">SQL语句</param>
        /// <returns></returns>
        public static DataSet ExecuteDataset(string connectionString, stringSQLString)
        {
            using (SqlConnection conn = newSqlConnection(connectionString))
            {
                DataSet ds = newDataSet();
                try{
                    conn.Open();
                    SqlDataAdapter da = newSqlDataAdapter(SQLString, conn);
                    da.Fill(ds, "ds");
                }
                catch{
                    throw;
                }
                returnds;
            }
        }

        /// <summary>
        ///执行数据集
        /// </summary>
        /// <param name="conn">连接字符串</param>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">命令文本</param>
        /// <param name="commandParameters">参数</param>
        /// <returns></returns>
        public static DataSet ExecuteDataset(SqlConnection conn, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {
            DataSet ds = newDataSet();
            SqlCommand cmd = newSqlCommand();
            try{
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);

                SqlDataAdapter da = newSqlDataAdapter(cmd);
                
                da.Fill(ds);
                cmd.Parameters.Clear();
                da.Dispose();
            }
            catch{
                throw;
            }
            returnds;
        }
        #endregion ExecuteDataset

        /// <summary>
        ///执行SQL语句
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="SQLString">SQL语句</param>
        /// <returns></returns>
        public static int ExecuteSql(string connectionString, stringSQLString)
        {
            ILog logger = LogManager.GetLogger("SQLHelper");
            logger.Info("ExecuteSql:" +SQLString);
            using (SqlConnection connection = newSqlConnection(connectionString))
            {
                using (SqlCommand cmd = newSqlCommand(SQLString, connection))
                {
                    try{
                        connection.Open();
                        int rows =cmd.ExecuteNonQuery();
                        returnrows;
                    }
                    catch{
                        throw;

                    }
                }
            }
        }

        /// <summary>
        ///执行一条记录
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="SQLString">SQL语句</param>
        /// <returns></returns>
        public static int ExecuteScalar(string connectionString, stringSQLString)
        {
            using (SqlConnection connection = newSqlConnection(connectionString))
            {
                using (SqlCommand cmd = newSqlCommand(SQLString, connection))
                {
                    try{
                        connection.Open();
                        int var = int.Parse(cmd.ExecuteScalar().ToString());
                        return var;
                    }
                    catch{
                        throw;

                    }
                }
            }
        }

        /// <summary>
        ///执行多条SQL语句,实现数据库事务。
        /// </summary>
        /// <param name="SQLStringList">多条SQL语句</param>        
        public static int ExecuteSqlTran(string connectionString, List<String>SQLStringList)
        {
            using (SqlConnection connection = newSqlConnection(connectionString))
            {
                string strsql = "";
                connection.Open();
                SqlCommand cmd = newSqlCommand();
                cmd.Connection =connection;
                SqlTransaction tx =connection.BeginTransaction();
                cmd.Transaction =tx;
                try{
                    int count = 0;
                    for (int n = 0; n < SQLStringList.Count; n++)
                    {
                        strsql =SQLStringList[n];
                        if (strsql.Trim().Length > 1)
                        {
                            cmd.CommandText =strsql;
                            count +=cmd.ExecuteNonQuery();
                        }
                    }
                    tx.Commit();
                    connection.Close();
                    returncount;
                }
                catch{
                    tx.Rollback();
                    connection.Close();
                    return -1;
                }
            }
        }

        /// <summary>
        ///一般用于父子表的插入,并且父表的主键是自增型。
        ///如果identityParam不为空,则arrCommandText[0]必须存在Identity字段,arrParam[1..n]中应该存在名为identityParam的参数
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="commandType">命令类型</param>
        /// <param name="arrCommandText">多条SQL语句</param>
        /// <param name="arrParam">参数列表</param>
        /// <param name="identityParam">null或""表示无父子关系</param>
        public static void ExecuteNonQuery(string connectionString, CommandType commandType, List<string> arrCommandText, List<SqlParameter[]> arrParam, stringidentityParam)
        {
            SqlConnection connection = newSqlConnection(connectionString);
            connection.Open();
            SqlTransaction tran =connection.BeginTransaction();
            try{
                SqlParameter[] paras;
                int identityValue = 0;

                for (int i = 0; i < arrCommandText.Count; i++)
                {
                    if (arrCommandText[i].ToString() != "")
                    {
                        paras = arrParam == null ? null: arrParam[i];
                        if (i > 0 && paras != null && !string.IsNullOrEmpty(identityParam))
                        {
                            identityParam =identityParam.ToLower();
                            for (int j = 0; j < paras.Length; j++)
                            {
                                if (paras[j].ParameterName.ToLower() ==identityParam)
                                {
                                    paras[j].Value =identityValue;
                                    break;
                                }
                            }
                        }

                        if (i == 0 && !string.IsNullOrEmpty(identityParam))
                        {
                            if (commandType ==CommandType.Text)
                                identityValue = Convert.ToInt32(ExecuteScalar(tran, commandType, (arrCommandText[i].ToLower().TrimEnd(";
".ToCharArray()).EndsWith("@@identity") ? arrCommandText[i] : arrCommandText[i].TrimEnd(";
".ToCharArray()) + ";select @@IDENTITY"), paras));
                            elseidentityValue =Convert.ToInt32(ExecuteScalar(tran, commandType, arrCommandText[i], paras));
                        }
                        elseExecuteNonQuery(tran, commandType, arrCommandText[i], paras);
                    }
                }

                tran.Commit();
            }
            catch(Exception e)
            {
                tran.Rollback();
                throwe;
            }
            finally{
                if (connection.State ==ConnectionState.Open)
                    connection.Close();
            }
        }

        /// <summary>
        ///Execute a SqlCommand (that returns no resultset) against the database specified in the connection string 
        ///using the provided parameters.
        /// </summary>
        /// <remarks>
        ///e.g.:  
        ///int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">a valid connection string for a SqlConnection</param>
        /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">the stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        /// <returns>an int representing the number of rows affected by the command</returns>
        public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {

            SqlCommand cmd = newSqlCommand();

            using (SqlConnection conn = newSqlConnection(connectionString))
            {
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                int val =cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                returnval;
            }
        }

        /// <summary>
        ///Execute a SqlCommand (that returns no resultset) against an existing database connection 
        ///using the provided parameters.
        /// </summary>
        /// <remarks>
        ///e.g.:  
        ///int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="conn">an existing database connection</param>
        /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">the stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        /// <returns>an int representing the number of rows affected by the command</returns>
        public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {
            

            SqlCommand cmd = newSqlCommand();

            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            int val =cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            returnval;
        }

        /// <summary>
        ///Execute a SqlCommand (that returns no resultset) using an existing SQL Transaction 
        ///using the provided parameters.
        /// </summary>
        /// <remarks>
        ///e.g.:  
        ///int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="trans">an existing sql transaction</param>
        /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">the stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        /// <returns>an int representing the number of rows affected by the command</returns>
        public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {
            SqlCommand cmd = newSqlCommand();
            PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
            int val =cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();
            returnval;
        }

        /// <summary>
        ///执行一条只读记录
        /// </summary>
        /// <param name="trans">事务</param>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">SQL语句</param>
        /// <param name="commandParameters">参数</param>
        /// <returns></returns>
        public static SqlDataReader ExecuteReader(SqlTransaction trans, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {
            SqlCommand cmd = newSqlCommand();
            PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
            SqlDataReader rdr =cmd.ExecuteReader();
            cmd.Parameters.Clear();
            ICollection<string> Categories = new List<string>() { "3"};
            Logger.Write("ExecuteReader:" + cmdText, Categories, 3, 0, TraceEventType.Error, "", "", "", "", "", null);
            returnrdr;
        }

        /// <summary>
        ///日志写
        /// </summary>
        /// <param name="log">用户</param>
        public static void LogWriter(stringlog)
        {
               ICollection<string> Categories = new List<string>() { "4"};
               Logger.Write("user:" + log, Categories, 4, 0, TraceEventType.Error, "", "", "", "", "", null);          
        }

        /// <summary>
        ///Execute a SqlCommand that returns a resultset against the database specified in the connection string 
        ///using the provided parameters.
        /// </summary>
        /// <remarks>
        ///e.g.:  
        ///SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">a valid connection string for a SqlConnection</param>
        /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">the stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        /// <returns>A SqlDataReader containing the results</returns>
        public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {
            SqlCommand cmd = newSqlCommand();
            SqlConnection conn = newSqlConnection(connectionString);

            //we use a try/catch here because if the method throws an exception we want to 
            //close the connection throw code, because no datareader will exist, hence the 
            //commandBehaviour.CloseConnection will not work
            try{
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
                SqlDataReader rdr =cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                //ICollection<string> Categories = new List<string>() { "3" };
                //Logger.Write("ExecuteReader:" + cmdText, Categories, 3, 0, TraceEventType.Error, "", "", "", "", "", null);
                returnrdr;
            }
            catch{
                conn.Close();
                throw;
            }
        }

        /// <summary>
        ///Execute a SqlCommand that returns the first column of the first record against the database specified in the connection string 
        ///using the provided parameters.
        /// </summary>
        /// <remarks>
        ///e.g.:  
        ///Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="connectionString">a valid connection string for a SqlConnection</param>
        /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">the stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        /// <returns>An object that should be converted to the expected type using Convert.To{Type}</returns>
        public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {
            SqlCommand cmd = newSqlCommand();

            using (SqlConnection connection = newSqlConnection(connectionString))
            {
                PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
                object val =cmd.ExecuteScalar();
                cmd.Parameters.Clear();
                returnval;
            }
        }

        /// <summary>
        ///Execute a SqlCommand (that returns a 1x1 resultset) against the specified SqlTransaction
        ///using the provided parameters.
        /// </summary>
        /// <remarks>
        ///e.g.:  
        ///int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="transaction">A valid SqlTransaction</param>
        /// <param name="commandType">The CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">The stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">An array of SqlParamters used to execute the command</param>
        /// <returns>An object containing the value in the 1x1 resultset generated by the command</returns>
        public static object ExecuteScalar(SqlTransaction transaction, CommandType commandType, string commandText, paramsSqlParameter[] commandParameters)
        {
            if (transaction == null) throw new ArgumentNullException("transaction");
            if (transaction != null && transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");

            //Create a command and prepare it for execution
            SqlCommand cmd = newSqlCommand();
            PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters);

            //Execute the command & return the results
            object retval =cmd.ExecuteScalar();

            //Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear();
            returnretval;
        }

        /// <summary>
        ///Execute a SqlCommand that returns the first column of the first record against an existing database connection 
        ///using the provided parameters.
        /// </summary>
        /// <remarks>
        ///e.g.:  
        ///Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
        /// </remarks>
        /// <param name="conn">an existing database connection</param>
        /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">the stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
        /// <returns>An object that should be converted to the expected type using Convert.To{Type}</returns>
        public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, paramsSqlParameter[] commandParameters)
        {

            SqlCommand cmd = newSqlCommand();

            PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
            ILog logger = LogManager.GetLogger("SQLHelper");
            logger.Info("ExecuteScalar:" +cmdText );

            object val =cmd.ExecuteScalar();
            cmd.Parameters.Clear();
            returnval;
        }

        /// <summary>
        ///add parameter array to the cache
        /// </summary>
        /// <param name="cacheKey">Key to the parameter cache</param>
        /// <param name="cmdParms">an array of SqlParamters to be cached</param>
        public static void CacheParameters(string cacheKey, paramsSqlParameter[] commandParameters)
        {
            parmCache[cacheKey] =commandParameters;
        }

        /// <summary>
        ///Retrieve cached parameters
        /// </summary>
        /// <param name="cacheKey">key used to lookup parameters</param>
        /// <returns>Cached SqlParamters array</returns>
        public static SqlParameter[] GetCachedParameters(stringcacheKey)
        {
            SqlParameter[] cachedParms =(SqlParameter[])parmCache[cacheKey];

            if (cachedParms == null)
                return null;

            SqlParameter[] clonedParms = newSqlParameter[cachedParms.Length];

            for (int i = 0, j = cachedParms.Length; i < j; i++)
                clonedParms[i] =(SqlParameter)((ICloneable)cachedParms[i]).Clone();

            returnclonedParms;
        }

        /// <summary>
        ///Prepare a command for execution
        /// </summary>
        /// <param name="cmd">SqlCommand object</param>
        /// <param name="conn">SqlConnection object</param>
        /// <param name="trans">SqlTransaction object</param>
        /// <param name="cmdType">Cmd type e.g. stored procedure or text</param>
        /// <param name="cmdText">Command text, e.g. Select * from Products</param>
        /// <param name="cmdParms">SqlParameters to use in the command</param>
        private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, stringcmdText, SqlParameter[] cmdParms)
        {

            if (conn.State !=ConnectionState.Open)
                conn.Open();

            cmd.Connection =conn;
            cmd.CommandText =cmdText;

            if (trans != null)
                cmd.Transaction =trans;

            cmd.CommandType =cmdType;

            if (cmdParms != null)
            {
                foreach (SqlParameter parm incmdParms)
                    cmd.Parameters.Add(parm);
            }
        }

        /// <summary>
        ///过滤通配符
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string FmLike(stringtext)
        {
            return text.Replace("%", "[%]").Replace("_", "[_]");
        }
    }

免责声明:文章转载自《c# SQLHelper总汇》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Python与开源GIS量子计算核心突破!Shor算法实现或使密码成摆设下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Java IO流字符流简介及基本使用

                Java IO流字符流简介及常用字符流的基本使用     字符流分为输入字符流(Writer)和输出字符流(Reader),这两种字符流及其子类字符流都有自己专门的功能。在编码中我们常用的输出字符流有FileWriter、PrintWriter等,而常用的输入字符流有StringReader、FileReader、Buffe...

WebApi使用Token(OAUTH 2.0方式)

1.在项目中添加引用 Microsoft.AspNet.WebApi.Owin Microsoft.Owin.Host.SystemWeb Microsoft.Owin.Security.OAuth Microsoft.Owin.Security.Cookies Microsoft.AspNet.Identity.Owin Microsoft.Owin.C...

pb常用函数(二)(转)

  GetFocus()功能确定当前焦点位于哪个控件上。语法GetFocus ( )返回值GraphicObject。函数执行成功时返回当前得到焦点控件的引用,发生错误时返回无效引用。用法应用程序利用IsValid()函数可以检测GetFocus()是否返回有效的控件引用。同时,使用TypeOf()函数可以确定控件的类型。Post()功能将指定消息加入到某...

使用JDBC进行简单的增删改查

JDBC为java的基础。用jdbc实现对数据库的增删改查的功能是程序员的基本要求。本例以mysql为例,首先要使用本例需要添加mysql-connector-java-5.1.7-bin.jar包。专门用来加载jdbc的驱动。如果数据库为oracle,相应的jar包换为ojdbc6.jar。 通过下面的代码可以练习一下,掌握jdbc的使用方法,自己可以对...

SpringBoot Controller接收参数的几种常用方式

第一类:请求路径参数 1. @PathVariable 获取路径参数。即url/{id}这种形式。 2. @RequestParam 获取查询参数。即url?name=这种形式 例子 GEThttp://localhost:8080/demo/123?name=suki_rong对应的java代码 @GetMapping("/demo/{id}") pub...

ES6 阮一峰阅读学习

参考: ECMAScript6入门   就是随便看看,了解一下。 一、ECMAScript6简介 1. 什么是ECMAScript6? JavaScript语言的下一代标准。2015年6月发布,正式名称是《ECMAScript2015标准》。 思考:编程语言和英语、法语语言差不多吧。其实就是语言的标准、规范之类,和英语语法差不多的东西吧 = =! 二、le...