Class MybatisEnumTypeHandler<E extends Enum<E>>

java.lang.Object
org.apache.ibatis.type.TypeReference<T>
org.apache.ibatis.type.BaseTypeHandler<E>
top.tangyh.basic.database.mybatis.handlers.MybatisEnumTypeHandler<E>
Type Parameters:
E - 枚举类型
All Implemented Interfaces:
org.apache.ibatis.type.TypeHandler<E>

public class MybatisEnumTypeHandler<E extends Enum<E>> extends org.apache.ibatis.type.BaseTypeHandler<E>
自定义枚举属性转换器
Since:
2017-10-11
Author:
hubin
  • Constructor Details

    • MybatisEnumTypeHandler

      public MybatisEnumTypeHandler(Class<E> enumClassType)
  • Method Details

    • findEnumValueFieldName

      public static Optional<String> findEnumValueFieldName(Class<?> clazz)
      查找标记标记EnumValue字段
      Parameters:
      clazz - class
      Returns:
      EnumValue字段
      Since:
      3.3.1
    • isMpEnums

      public static boolean isMpEnums(Class<?> clazz)
      判断是否为MP枚举处理
      Parameters:
      clazz - class
      Returns:
      是否为MP枚举处理
      Since:
      3.3.1
    • setNonNullParameter

      public void setNonNullParameter(PreparedStatement ps, int i, E parameter, org.apache.ibatis.type.JdbcType jdbcType) throws SQLException
      Specified by:
      setNonNullParameter in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E>>
      Throws:
      SQLException
    • getNullableResult

      public E getNullableResult(ResultSet rs, String columnName) throws SQLException
      Specified by:
      getNullableResult in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E>>
      Throws:
      SQLException
    • getNullableResult

      public E getNullableResult(ResultSet rs, int columnIndex) throws SQLException
      Specified by:
      getNullableResult in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E>>
      Throws:
      SQLException
    • getNullableResult

      public E getNullableResult(CallableStatement cs, int columnIndex) throws SQLException
      Specified by:
      getNullableResult in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E>>
      Throws:
      SQLException
    • equalsValue

      protected boolean equalsValue(Object sourceValue, Object targetValue)
      值比较
      Parameters:
      sourceValue - 数据库字段值
      targetValue - 当前枚举属性值
      Returns:
      是否匹配
      Since:
      3.3.0