StatementHandler
StatementHandler接口是Mybatis的核心接口之一,它完成了Mybatis中最核心的一部分工作,也是后面介绍的Executor接口实现的基础。
StatementHandler接口中的功能很多,例如创建Statement对象,为SQL语句绑定实参,执行select、update、insert、delete等多种类型的SQL语句,批量执行SQL语句,将结果集映射成结果对象。
StatementHandler接口的定义如下:
/**
* StatementHandler接口中的功能很多,例如创建Statement对象,为SQL语句绑定实参,
* 执行select、update、insert、delete等多种类型的SQL语句,批量执行SQL语句,将结果集映射成结果对象。
* 语句处理器
* @author Clinton Begin
*/
public interface StatementHandler {
/**
* 从连接中获取一个Statement
*/
Statement prepare(Connection connection, Integer transactionTimeout)
throws SQLException;
/**
* 绑定statement执行时所需的参数
* @param statement
* @throws SQLException
*/
void parameterize(Statement statement)
throws SQLException;
/**
* 批量执行SQL语句
* @param statement
* @throws SQLException
*/
void batch(Statement statement)
throws SQLException;
/**
* 执行update、insert、delete语句
* @param statement
* @return
* @throws SQLException
*/
int update(Statement statement)
throws SQLException;
/**
* 执行select语句
* @param statement
* @param resultHandler
* @param <E>
* @return
* @throws SQLException
*/
<E> List<E> query(Statement statement, ResultHandler resultHandler)
throws SQLException;
/**
* 查询游标
* @param statement
* @param <E>
* @return
* @throws SQLException
*/
<E> Cursor<E> queryCursor(Statement statement)
throws SQLException;
/**
* 获取绑定的SQL
* @return
*/
BoundSql getBoundSql();
/**
* 获取ParameterHandler
* @return
*/
ParameterHandler getParameterHandler();
}
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!