mybatis中statementHandler的设计与实现

    科技2025-01-22  13

    StatementHandler接口定义为

    Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException; void parameterize(Statement statement) throws SQLException; void batch(Statement statement) throws SQLException; int update(Statement statement) throws SQLException; <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException; <E> Cursor<E> queryCursor(Statement statement) throws SQLException; BoundSql getBoundSql(); ParameterHandler getParameterHandler();

    类结构图为

    RoutingStatementHandler起代理作用,根据不同的语句类型创建不同BaseStatementHandler子类。

    PreparedStatementHandler用于处理带有占位符的语句,SimpleStatementHandler处理不带占位符的,CallableStatementHandler处理存储过程调用语句

     

    Processed: 0.011, SQL: 8