现在的位置: 首页 > 综合 > 正文

将ibatis.net中定义的statement转换为实际的sql语句

2013年10月11日 ⁄ 综合 ⁄ 共 468字 ⁄ 字号 评论关闭

 

有时我们需要查看ibatisnet中statement生成的实际sql语句,
可以通过下面的方式取得:

public static string GetSql(string statementName, object paramObject)

{

       ISqlMapper mapper = Mapper.Instance();

       IMappedStatement statement = mapper.GetMappedStatement(statementName);

       if (!mapper.IsSessionStarted)

       {

           mapper.OpenConnection();

       }

       RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, mapper.LocalSession);

 

       return scope.PreparedStatement.PreparedSql;

}

抱歉!评论已关闭.