在执行器中,都会获取声明处理器:
public StatementHandler newStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameterObject, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
StatementHandler statementHandler = new RoutingStatementHandler(executor, mappedStatement, parameterObject, rowBounds, resultHandler, boundSql);
statementHandler = (StatementHandler) interceptorChain.pluginAll(statementHandler);
return statementHandler;
}
statementHandler = (StatementHandler) interceptorChain.pluginAll(statementHandler);
使用拦截器,声明处理可以定义插件
使用路由声明处理器,可以获取SimpleStatementHandler、PreparedStatementHandler、CallableStatementHandler三大处理器。
到底使用哪个处理器,是由ms.getStatementType参数决定,默认是
mappedStatement.statementType = StatementType.PREPARED;
在mapper里面的执行语句 xml标签中可以配置statementType属性:
Any one of STATEMENT, PREPARED or CALLABLE.
This causes MyBatis to use Statement,
PreparedStatement or CallableStatement
respectively.
Default: PREPARED.
BaseStatementHandler
声明处理器基类,主要是产生 :
protected final TypeHandlerRegistry typeHandlerRegistry; //类型处理注册
protected final ResultSetHandler resultSetHandler; //结果处理
protected final ParameterHandler parameterHandler; //参数处理
另外还准备Statement,具体由各个处理器生成instantiateStatement