mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
fix: 没有全局 TypeHandler 时再去处理属性。
This commit is contained in:
parent
85c410f8ce
commit
60da8edb7a
@ -38,7 +38,6 @@ import com.mybatisflex.core.util.StringUtil;
|
||||
import org.apache.ibatis.io.ResolverUtil;
|
||||
import org.apache.ibatis.reflection.Reflector;
|
||||
import org.apache.ibatis.reflection.TypeParameterResolver;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeException;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
@ -286,6 +285,11 @@ public class TableInfoFactory {
|
||||
|
||||
FlexGlobalConfig config = FlexGlobalConfig.getDefaultConfig();
|
||||
|
||||
TypeHandlerRegistry typeHandlerRegistry = null;
|
||||
if (config.getConfiguration() != null) {
|
||||
typeHandlerRegistry = config.getConfiguration().getTypeHandlerRegistry();
|
||||
}
|
||||
|
||||
for (Field field : entityFields) {
|
||||
|
||||
Class<?> fieldType = reflector.getGetterType(field.getName());
|
||||
@ -305,11 +309,17 @@ public class TableInfoFactory {
|
||||
|
||||
Column columnAnnotation = field.getAnnotation(Column.class);
|
||||
|
||||
|
||||
//满足以下 3 种情况,不支持该类型的属性自动映射为字段
|
||||
if ((columnAnnotation == null || columnAnnotation.typeHandler() == UnknownTypeHandler.class) // 未配置 typeHandler
|
||||
&& !fieldType.isEnum() // 类型不是枚举
|
||||
&& !defaultSupportColumnTypes.contains(fieldType) //默认的自动类型不包含该类型
|
||||
/*
|
||||
* 满足以下 4 种情况,不支持该类型的属性自动映射为字段
|
||||
* 1、注解上未配置 TypeHandler
|
||||
* 2、类型不是枚举
|
||||
* 3、默认的自动类型不包含该类型
|
||||
* 4、没有全局 TypeHandler
|
||||
*/
|
||||
if ((columnAnnotation == null || columnAnnotation.typeHandler() == UnknownTypeHandler.class)
|
||||
&& !fieldType.isEnum()
|
||||
&& !defaultSupportColumnTypes.contains(fieldType)
|
||||
&& (typeHandlerRegistry == null || !typeHandlerRegistry.hasTypeHandler(fieldType))
|
||||
) {
|
||||
// 忽略 集合 实体类 解析
|
||||
if (columnAnnotation != null && columnAnnotation.ignore()) {
|
||||
@ -434,9 +444,7 @@ public class TableInfoFactory {
|
||||
// 非集合类型
|
||||
else {
|
||||
Class<?> typeHandlerClass = columnAnnotation.typeHandler();
|
||||
Configuration configuration = config.getConfiguration();
|
||||
if (configuration != null) {
|
||||
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
|
||||
if (typeHandlerRegistry != null) {
|
||||
Class<?> propertyType = columnInfo.getPropertyType();
|
||||
JdbcType jdbcType = columnAnnotation.jdbcType();
|
||||
if (jdbcType != JdbcType.UNDEFINED) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user