Mybatis source parsing --TypeHandler

type Handler

Responsible for converting between JAVA types and JDBC types, TypeHandler interface methods fall into two categories:

  1. void setParameter (): responsible for translating JAVA type JDBC type
  2. T getResult (): responsible for the data from a JDBC type to type JAVA

Abstract class BaseTypeHandler to provide Mybatis, the main achievement of its subclasses to achieve.
TypeHandler type conversion for performing a single column and a single parameter value.

Type Trades Register

  private final Map<JdbcType, TypeHandler<?>> JDBC_TYPE_HANDLER_MAP = new EnumMap<JdbcType, TypeHandler<?>>(JdbcType.class);
  private final Map<Type, Map<JdbcType, TypeHandler<?>>> TYPE_HANDLER_MAP = new ConcurrentHashMap<Type, Map<JdbcType, TypeHandler<?>>>();
  private final Map<Class<?>, TypeHandler<?>> ALL_TYPE_HANDLERS_MAP = new HashMap<Class<?>, TypeHandler<?>>();
  private static final Map<JdbcType, TypeHandler<?>> NULL_TYPE_HANDLER_MAP = Collections.emptyMap();

Overloaded by a plurality of register () method as an object in the set register typeHandler;
by a plurality overloaded getTypeHandler () acquired from the object corresponding to the four TypeHandler set;


Provides classes alias registration and management functions, use TYPE_ALIEASES field ( Map<String,Class<?>>type) manage the relationship between the alias and type java, use registerAlias () to complete the registration

Published 98 original articles · won praise 9 · views 10000 +

Guess you like