public IList<BookDetail> GetImpnoByBookno(string bookno)
{
//下面这句就是获得配置文件中sql的
string sql = GetRuntimeSql("SqlMapReader.config", "BookInfoDao.GetImpnoByBookno", bookno);
return Reader.QueryForList<BookDetail>("BookInfoDao.GetImpnoByBookno", bookno);
}
/// <summary>
/// 得到即时的sql语句
/// </summary>
/// <param name="readOrWriterName">sqlmap映射文件名</param>
/// <param name="statementName">调用的方法名</param>
/// <param name="paramObject">传入的参数</param>
/// <returns></returns>
public string GetRuntimeSql(string readOrWriterName, string statementName, object paramObject)
{
string result = string.Empty;
ISqlMapper sqlMapper = new DomSqlMapBuilder().Configure(readOrWriterName);
try
{
IMappedStatement statement = sqlMapper.GetMappedStatement(statementName);
if (!sqlMapper.IsSessionStarted)
{
sqlMapper.OpenConnection();
}
RequestScope scope = statement.Statement.Sql.GetRequestScope(statement, paramObject, sqlMapper.LocalSession);
result = scope.PreparedStatement.PreparedSql;
}
catch (Exception ex)
{
result = "获取SQL语句出现异常:" + ex.Message;
}
return result;
}
这里面用的几个类都是ibatis.dll提供的,无需自建。