mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
!475 kotlin代码生成器,FieldWrapper增加友好提示
Merge pull request !475 from 落羽er/main
This commit is contained in:
commit
c4cdf8c2dc
@ -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
|
||||
}
|
||||
|
||||
@ -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<out E>),并且传入的具体泛型类型为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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user