zoukankan      html  css  js  c++  java
  • Ibatis.Net 输出SQL语句学习(七)

    一、IBatis.net输出SQL语句

    输出IBatis.net生成的SQL语句,能够方便调试。

    在MapperHelper类中添加GetSql方法:

            /// <summary>
            /// 返回执行的Sql语句
            /// </summary>
            /// <param name="statementName"></param>
            /// <param name="paramObject"></param>
            /// <returns></returns>
            public static string GetSql(string statementName, object paramObject)
            {
                IMappedStatement statement = MapperHelper.Instance().GetMappedStatement(statementName);
                RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, MapperHelper.Instance().CreateSqlMapSession());
                return scope.PreparedStatement.PreparedSql;
            }

    在执行DAO方法之前添加:

      public IList<PersonModel> SelectPersonById(Hashtable ht)
            {
                string sql = MapperHelper.GetSql("SelectPersonById", ht);
                IList<PersonModel> pList = mapper.QueryForList<PersonModel>("SelectPersonById", ht);
                return pList;
            }

    在执行之前,得到执行Sql,可以记录日志方便调试等操作。

    参考:http://www.cnblogs.com/caoyc/category/873268.html

  • 相关阅读:
    ASP.Net Core -- 模型验证
    C# -- nameof什么意思?
    C# -- value是什么意思?
    C# -- 异常(二)
    C# -- 异常(一)
    C# -- 委托(二)
    C# -- 委托(一)
    ASP.Net Core -- Controller返回View
    ASP.Net Core -- 中间件
    ASP.Net Core -- 服务注册和管道
  • 原文地址:https://www.cnblogs.com/vanblog/p/8706764.html
Copyright © 2011-2022 走看看