Skip to content

TypeHandlerAssociations

GangCheng edited this page Jul 28, 2024 · 6 revisions

JdbcType To R2dbcType

  • By default, mybatis-r2dbc mapping JdbcType to R2dbcType by name.DefaultR2DbcTypeMappingFactory

  • You can configure other mappings or replace original mappings by using method in R2dbcMybatisConfiguration

    r2dbcMybatisConfiguration.registerR2dbcTypeMapping(JdbcType.xxx, R2dbcType.xxx);

R2dbcTypeHandlerAdapter

  • R2dbcTypeHandlerAdapter is used to customize type handler with r2dbc
  • The default implementations is R2dbcTypeHandlerAdapter Package
  • Register R2dbcTypeHandlerAdapter:
    r2dbcMybatisConfiguration.getR2dbcTypeHandlerAdapterRegistry().register( ... );
  • If both TypeHandler of mybatis3 and R2dbcTypeHandlerAdapter of mybatis-r2dbc exist, and you want force using R2dbcTypeHandlerAdapter, you need configure typehandler as below
    • For parameter map

      <parameterMap>
          <!-- ...... -->
          <parameter property="clobContent" jdbcType="CLOB" typeHandler="pro.chenggang.project.reactive.mybatis.support.r2dbc.executor.type.support.ForceToUseR2dbcTypeHandlerAdapter"/>
          <!-- or  with type alias -->
          <parameter property="clobContent" jdbcType="CLOB" typeHandler="ForceToUseR2dbcTypeHandlerAdapter"/>
      </parameterMap>
    • For result map

      <resultMap>
          <!-- ...... -->
          <result column="blob_content" property="blobContent" typeHandler="pro.chenggang.project.reactive.mybatis.support.r2dbc.executor.type.support.ForceToUseR2dbcTypeHandlerAdapter"/>
          <!-- or  with type alias -->
          <result column="blob_content" property="blobContent" typeHandler="ForceToUseR2dbcTypeHandlerAdapter"/>
      </resultMap>
    • Configure with R2dbcMybatisConfiguration

      r2dbcMybatisConfiguration.getTypeHandlerRegistry().register(Clob.class, JdbcType.CLOB, ForceToUseR2dbcTypeHandlerAdapter.class);
    • It also can be configured with annotation as well

MybatisTypeHandlerConverter