TypeHandler主要是用在从java数据写入数据库时,从数据库中读取数据时的从java到jdbc类型之间的转换。
其类层次图为

TypeHandler:主要定义了设置参数、根据列名获取参数,列索引获取参数,从CallableStatement中根据列索引获取参数。
BaseTypeHandler:处理非NULL值的设置及获取参数
其他子类实现对应类型设置及参数获取
TypeHandlerRegistry:处理type到TypeHandler的映射关系
默认的映射关系有
| javaType | jdbcType | typeHandler |
| Boolean.class | null | BooleanTypeHandler |
| boolean.class | null | BooleanTypeHandler |
| JdbcType.Boolean | BooleanTypeHandler | |
| JdbcType.BIT | BooleanTypeHandler | |
| Byte.class | null | ByteTypeHandler |
| byte.class | null | ByteTypeHandler |
| JdbcType.TINYINT | ByteTypeHandler | |
| Short.class | null | ShortTypeHandler |
| short.class | null | ShortTypeHandler |
| JdbcType.SMALLINT | ShortTypeHandler | |
| Integer.class | null | IntegerTypeHandler |
| int.class | null | IntegerTypeHandler |
| JdbcType.INTEGER | IntegerTypeHandler | |
| Long.class | null | LongTypeHandler |
| long.class | null | LongTypeHandler |
| Float.class | null | FloatTypeHandler |
| float.class | null | FloatTypeHandler |
| JdbcType.FLOAT | FloatTypeHandler | |
| Double.class | NULL | DoubleTypeHandler |
| double.class | NULL | DoubleTypeHandler |
| JdbcType.DOUBLE | DoubleTypeHandler | |
| Reader.class | null | ClobReaderTypeHandler |
| String.class | null | StringTypeHandler |
| String.class | JdbcType.CHAR | StringTypeHandler |
| String.class | JdbcType.CLOB | ClobTypeHandler |
| String.class | JdbcType.VARCHAR | StringTypeHandler |
| String.class | JdbcType.LONGVARCHAR | StringTypeHandler |
| String.class | JdbcType.NVARCHAR | NStringTypeHandler |
| String.class | JdbcType.NCHAR | NStringTypeHandler |
| String.class | JdbcType.NCLOB | NClobTypeHandler |
| JdbcType.CHAR | StringTypeHandler | |
| JdbcType.VARCHAR | StringTypeHandler | |
| JdbcType.CLOB | ClobTypeHandler | |
| JdbcType.LONGVARCHAR | StringTypeHandler | |
| JdbcType.NVARCHAR | NStringTypeHandler | |
| JdbcType.NCHAR | NStringTypeHandler | |
| JdbcType.NCLOB | NClobTypeHandler | |
| Object.class | JdbcType.ARRAY | ArrayTypeHandler |
| JdbcType.ARRAY | ArrayTypeHandler | |
| BigInteger.class | null | BigIntegerTypeHandler |
| JdbcType.BIGINT | LongTypeHandler | |
| BigDecimal | null | BigDecimalTypeHandler |
| JdbcType.REAL | BigDecimalTypeHandler | |
| JdbcType.DECIMAL | BigDecimalTypeHandler | |
| JdbcType.NUMERIC | BigDecimalTypeHandler | |
| InputStream.class | null | BlobInputStreamTypeHandler |
| Byte[].class | null | ByteObjectArrayTypeHandler |
| Byte[].class | JdbcType.BLOB | BlobByteObjectArrayTypeHandler |
| Byte[].class | JdbcType.LONGVARBINARY | BlobByteObjectArrayTypeHandler |
| byte[].class | null | ByteArrayTypeHandler |
| byte[].class | JdbcType.BLOB | BlobTypeHandler |
| byte[].class | JdbcType.LONGVARBINARY | BlobTypeHandler |
| JdbcType.BLOB | BlobTypeHandler | |
| JdbcType.LONGVARBINARY | BlobTypeHandler | |
| Date.class | null | DateTypeHandler |
| Date.class | JdbcType.DATE | DateOnlyTypeHandler |
| Date.class | JdbcType.TIME | TimeOnlyTypeHandler |
| JdbcType.TIMESTAMP | DateTypeHandler | |
| JdbcType.DATE | DateOnlyTypeHandler | |
| JdbcType.TIME | TimeOnlyTypeHandler | |
| java.sql.Date.class | null | SqlDateTypeHandler |
| java.sql.Time.class | null | SqlTimeTypeHandler |
| java.sql.Timestamp.class | null | SqlTimestampTypeHandler |
| String.class | JdbcType.SQLXML | SqlxmlTypeHandler |
| Instant.class | null | InstantTypeHandler |
| LocalDateTime.class | null | LocalDateTimeTypeHandler |
| LocalDate.class | null | LocalDateTypeHandler |
| LocalTime.class | null | LocalTimeTypeHandler |
| OffsetDateTime.class | null | OffsetDateTimeTypeHandler |
| OffsetTime.class | null | OffsetTimeTypeHandler |
| ZoneDateTime.class | null | ZoneDateTimeTypeHandler |
| Month.class | null | MonthTypeHandler |
| Year.class | null | YearTypeHandler |
| YearMonth.class | null | YearMonthTypeHandler |
| JapaneseDate.class | null | JapaneseDateTypeHandler |
| Character.class | null | CharacterTypeHandler |
| char.class | null | CharacterTypeHandler |
版权声明:本文为wuli2496原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。