From ef3a5fd71c25083e87bcab981a5e37ebf0c145c4 Mon Sep 17 00:00:00 2001 From: rainy Date: Thu, 18 Jul 2024 11:46:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?kotlin=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=99=A8=20entity=E7=B1=BB=E5=AE=9A=E4=B9=89=E5=8F=8A=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=AE=BE=E7=BD=AE=E4=B8=BAopen=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/templates/enjoy/entity.kotlin.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.kotlin.tpl b/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.kotlin.tpl index ea2317ff..15fa5686 100644 --- a/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.kotlin.tpl +++ b/mybatis-flex-codegen/src/main/resources/templates/enjoy/entity.kotlin.tpl @@ -27,7 +27,7 @@ import io.swagger.v3.oas.annotations.media.Schema */ #(table.buildTableAnnotation()) #end -#if(isBase)open #end class #(entityClassName) #if(withActiveRecord) : Model<#(entityClassName)>()#else#(table.buildKtExtends(isBase))#end { +open class #(entityClassName) #if(withActiveRecord) : Model<#(entityClassName)>()#else#(table.buildKtExtends(isBase))#end { #for(column : table.columns) #set(comment = javadocConfig.formatColumnComment(column.comment)) #if(isNotBlank(comment)) @@ -45,7 +45,7 @@ import io.swagger.v3.oas.annotations.media.Schema #if(withSwagger && swaggerVersion.getName() == "DOC") @Schema(description = "#(column.comment)") #end - #if(isBase)open #end var #(column.property): #(column.propertySimpleType)? = #if(isNotBlank(column.propertyDefaultValue)) = #(column.propertyDefaultValue)#else null#end + open var #(column.property): #(column.propertySimpleType)? = #if(isNotBlank(column.propertyDefaultValue)) = #(column.propertyDefaultValue)#else null#end #end } From 6a3dafd160bc9893e49524589a6f09f73e8d981d Mon Sep 17 00:00:00 2001 From: rainy Date: Thu, 18 Jul 2024 11:46:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?FieldWrapper=20=E8=8E=B7=E5=8F=96Collection?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E7=B1=BB=E5=9E=8B=E6=97=B6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=8B=E5=A5=BD=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mybatisflex/core/util/FieldWrapper.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java index 6a26c917..d5446a0f 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/FieldWrapper.java @@ -94,9 +94,15 @@ public class FieldWrapper { if (Collection.class.isAssignableFrom(fieldType)) { Type genericType = field.getGenericType(); - if (genericType instanceof ParameterizedType) { - Type actualTypeArgument = ((ParameterizedType) genericType).getActualTypeArguments()[0]; - fieldWrapper.mappingType = (Class) actualTypeArgument; + try{ + //使用Kotlin时,若Collection泛型类型为协变类型时(如 List),并且传入的具体泛型类型为open,genericType的具体类型为WildcardType(? extends ExampleClass),该类型不可转为Class(无具体类型),使用instanceOf会抛出转换异常。 + //该错误目前只在以上情况中发现 + if (genericType instanceof ParameterizedType) { + Type actualTypeArgument = ((ParameterizedType) genericType).getActualTypeArguments()[0]; + fieldWrapper.mappingType = (Class) actualTypeArgument; + } + }catch (ClassCastException e){ + throw new UnsupportedOperationException(String.format("不支持使用[%s]作为集合类型。请使用MutableList",fieldType.getName())); } } else if (Map.class.isAssignableFrom(fieldType)) { Type genericType = field.getGenericType();