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

  • 相关阅读:
    地区列表
    storyboard
    快捷键2
    关于本地缓存
    深入浅出Cocoa之消息
    ARC和Non-ARC下的单例模式
    runloop原理介绍
    ARC内存管理机制详解
    解决UITableViewCell separator左侧不贴边
    UICollectionView的使用
  • 原文地址:https://www.cnblogs.com/vanblog/p/8706764.html
Copyright © 2011-2022 走看看