1.通过SqlMapClientDaoSupport,SqlMapClientImpl,MappedStatement,Sql,RequestScope等ibatis提供的类
?
/** * 获得sql * @param db 通过它获取SqlMapClient * @param param sql里面的参数 * @param sqlName Statement的ID * @return */ public String getCurrSql(DBOperation db,Map<String, String> param,String sqlName) { String sql = null; SqlMapClientImpl sqlmap = (SqlMapClientImpl) db.getSqlMapClient(); MappedStatement stmt = sqlmap.getMappedStatement(sqlName); Sql stmtSql = stmt.getSql(); RequestScope requestScope = new RequestScope(); requestScope.setStatement(stmt); sql = stmtSql.getSql(requestScope, param); return sql; }
?
2.通过SqlMapExecutorDelegate,MappedStatement,Sql,RequestScope等ibatis提供的类
/** * 获得sql * @param db 通过它获取SqlMapClient * @param param sql里面的参数 * @param sqlName Statement的ID * @return */ public String getCurrSqlTwo(DBOperation db,Map<String, String> param,String sqlName) { SqlMapExecutorDelegate delegate=((ExtendedSqlMapClient) (db.getSqlMapClient())).getDelegate(); MappedStatement ms = delegate.getMappedStatement(sqlName); Sql sql=ms.getSql(); RequestScope requestScope = new RequestScope(); requestScope.setStatement(ms); String sqlStr = sql.getSql(requestScope,param); return sqlStr; }?
?