一、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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步