开发一个功能需要把ibatis的执行语句给记录下来。
public static String getCreateSql(SqlMapClientDaoSupport client,String key, Object param) {
SqlMapClientImpl sqlmap = (SqlMapClientImpl) client.getSqlMapClient(); MappedStatement stmt = sqlmap.getMappedStatement(key);
Sql sql = stmt.getSql(); RequestScope requestScope = new RequestScope();
requestScope.setStatement(stmt);
String sqlStr = null;

if (param == null) {
sqlStr = sql.getSql(requestScope, null);
} else {
sqlStr = sql.getSql(requestScope, param);
}
         
return sqlStr; }
写了一个方法  SqlMapClientDaoSupport client 这个参数
如以下这个实现类继承了 SqlMapClientDaoSupport 用来执行 ibatis 的调用
public class HeadCodeDaoImpl extends SqlMapClientDaoSupport
这里在要用到的方法中传入this.
sql = GetIbatisSql.getCreateSql(this, "insertHeadCode", headCode);
String key 这调用ibatis的 key值
Object param为给ibatis语句封装的参数
————————————————————————————————
注意一点
ibatis 执行语句如果写成
delete from tabel where id=#id#
那得到的语句 这 delete from tabel where id= ?
不符合条件。这时可以写成
delete form table where id ='$id$'
得到语句delete from tabel where id= 1(如果id 为1 的话)#号与$ 的区号是
##,这种格式的是字符串,会自动在内容两端加上单引号,$$表示的是原样输出,如果要求的是数值,所以要用$$
这里的话如果有要求语句原样要用$