-
Notifications
You must be signed in to change notification settings - Fork 15
TypeHandlerAssociations
GangCheng edited this page Jul 28, 2024
·
6 revisions
-
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
is used to customize type handler with r2dbc - The default implementations is R2dbcTypeHandlerAdapter Package
- Register R2dbcTypeHandlerAdapter:
r2dbcMybatisConfiguration.getR2dbcTypeHandlerAdapterRegistry().register( ... );
- If both
TypeHandler
ofmybatis3
andR2dbcTypeHandlerAdapter
ofmybatis-r2dbc
exist, and you want force usingR2dbcTypeHandlerAdapter
, you need configuretypehandler
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
-
- If you already have
TypeHandler
ofmybatis3
with dynamic type like enums, you can useMybatisTypeHandlerConverter
to converterTypeHandler
toR2dbcTypeHandlerAdapter
-
EnumTypeHandler
andEnumOrdinalTypeHandler
have already configured byEnumMybatisTypeHandlerConverter
andEnumOrdinalMybatisTypeHandlerConverter
by default. - Against the internal default configuration in
mybatis-r2dbc
, all enums work correctly. - Enums Related Test
- Associated Concept
- Basic Operation Instruction
- Integration with Spring Framework