请问在ibatis里怎样得到sql语句。
MappedStatement里有个getSql()方法,不知道有那位大虾用过

解决方案 »

  1.   

    以下是转载,内容。你的问题我想可以有下面方法解决:IBatisNet和其他的ORMapping的工具相比较,可以说是一个sqlmap,所以在Why use iBATIS SQL Maps? 中有一条理由是 
    You already know SQL, why waste time learning something else? 
    所以在我们的实际框架中更多的地方需要得到SQL语句。在我的架构中有这样的接口: 
    复杂的SQL主要是查询,统计这样的功能接口:  
       DataTable GetDataTable(string tag, object paramObject) ;  
       string GetSql(string tag, object paramObject); 
    这样我们对于复杂的查询,统计等就可以使用DataTable来映射查询结果,这里介绍一下string GetSql(string tag, object paramObject)的实现。 
    代码如下: 
    获得的SQL 
    1public string GetSql(string tag, object paramObject) 
    2        { 
    3            IStatement statement = _sqlMap.GetMappedStatement(tag).Statement; 
    4            RequestScope request = statement.Sql.GetRequestScope(paramObject, 
    5                new SqlMapSession(_sqlMap.DataSource)); 
    6            return request.PreparedStatement.PreparedSql; 
    7        } 
    statement用于insert,Select,Update用于检查标识符,然后根据paramObject和tag组合成SQL.。
      

  2.   

    get the actual SQL string that would be used by a statement
      

  3.   

    这么好的orm都没人用过???
      

  4.   

    没h..那么火,呵呵.
    不过我好象解释了啊
    get the actual SQL string that would be used by a statement