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

  • 相关阅读:
    实验一
    BZOJ 2564
    P4557 [JSOI2018]战争
    移动自动化-Mac-IOS-appium环境搭建
    Node安装mac版本
    删除N天前文件和空文件
    Python之jsonpath模块
    性能学习
    参数化
    查找测试用例
  • 原文地址:https://www.cnblogs.com/vanblog/p/8706764.html
Copyright © 2011-2022 走看看