浏览代码

修复枚举数组解析错误问题 #150

zhou-hao 5 年之前
父节点
当前提交
3620ff9f70

+ 2 - 1
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/EasyOrmSqlBuilder.java

@@ -258,7 +258,8 @@ public class EasyOrmSqlBuilder {
             } else if (column.getJavaType() == boolean.class || column.getJavaType() == Boolean.class) {
                 column.setValueConverter(new BooleanValueConverter(column.getJdbcType()));
                 column.setProperty("typeHandler", NumberBooleanTypeHandler.class.getName());
-            } else if (column.getJavaType().isEnum()) {
+            } else if (column.getJavaType().isEnum() || (
+                    column.getJavaType().isArray() && column.getJavaType().getComponentType().isEnum())) {
                 //ignore
             } else if (TypeUtils.isNumberType(column)) { //数字
                 //数字

+ 5 - 5
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/jpa/JpaAnnotationParser.java

@@ -89,16 +89,16 @@ public class JpaAnnotationParser {
         });
 
         jdbcTypeConvert.add((type, property) -> {
-            boolean isArray = type.isArray();
+            Class<?> propertyType = property.getPropertyType();
+            boolean isArray = propertyType.isArray();
             if (isArray) {
-                type = type.getComponentType();
-
+                propertyType = propertyType.getComponentType();
             }
-            if (type.isEnum() && EnumDict.class.isAssignableFrom(type)) {
-                Class genType = ClassUtils.getGenericType(type);
+            if (propertyType.isEnum() && EnumDict.class.isAssignableFrom(propertyType)) {
                 if (isArray) {
                     return JDBCType.BIGINT;
                 }
+                Class<?> genType = ((EnumDict<?>) propertyType.getEnumConstants()[0]).getValue().getClass();
                 return jdbcTypeMapping.getOrDefault(genType, JDBCType.VARCHAR);
             }
             return null;