实现步骤:
1、写个类
2、构建SqlMapClientDaoSupport 参数对象
修改dao,使继承SqlMapClientDaoSupport,还要注入SqlMapClient 。代码如下:
3、在dao中这么调用:
1、写个类
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
import com.ibatis.sqlmap.engine.mapping.sql.stat.StaticSql;
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement;
public class GetSql {
public static String getMappedStatementSQL(String id,
SqlMapClientDaoSupport dao) {
String sql = null;
SqlMapClientImpl sqlmap = (SqlMapClientImpl) dao.getSqlMapClient();
MappedStatement stmt = sqlmap.getMappedStatement(id);
StaticSql staticSql = (StaticSql) stmt.getSql();
sql = staticSql.getSql(null, null);
return sql;
}
}
2、构建SqlMapClientDaoSupport 参数对象
修改dao,使继承SqlMapClientDaoSupport,还要注入SqlMapClient 。代码如下:
@SuppressWarnings("unchecked")
@Service("userDAO")
public class UserDAO extends SqlMapClientDaoSupport implements IUserDAO {
@Autowired
public UserDAO(SqlMapClient sqlMapClient) {
super.setSqlMapClient(sqlMapClient);
}
3、在dao中这么调用:
GetSql.getMappedStatementSQL("getAllUser", this);