mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08: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())
|
#(table.buildTableAnnotation())
|
||||||
#end
|
#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)
|
#for(column : table.columns)
|
||||||
#set(comment = javadocConfig.formatColumnComment(column.comment))
|
#set(comment = javadocConfig.formatColumnComment(column.comment))
|
||||||
#if(isNotBlank(comment))
|
#if(isNotBlank(comment))
|
||||||
@ -45,7 +45,7 @@ import io.swagger.v3.oas.annotations.media.Schema
|
|||||||
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
@Schema(description = "#(column.comment)")
|
@Schema(description = "#(column.comment)")
|
||||||
#end
|
#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
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
@ -94,10 +94,16 @@ public class FieldWrapper {
|
|||||||
|
|
||||||
if (Collection.class.isAssignableFrom(fieldType)) {
|
if (Collection.class.isAssignableFrom(fieldType)) {
|
||||||
Type genericType = field.getGenericType();
|
Type genericType = field.getGenericType();
|
||||||
|
try{
|
||||||
|
//使用Kotlin时,若Collection泛型类型为协变类型时(如 List<out E>),并且传入的具体泛型类型为open,genericType的具体类型为WildcardType(? extends ExampleClass),该类型不可转为Class(无具体类型),使用instanceOf会抛出转换异常。
|
||||||
|
//该错误目前只在以上情况中发现
|
||||||
if (genericType instanceof ParameterizedType) {
|
if (genericType instanceof ParameterizedType) {
|
||||||
Type actualTypeArgument = ((ParameterizedType) genericType).getActualTypeArguments()[0];
|
Type actualTypeArgument = ((ParameterizedType) genericType).getActualTypeArguments()[0];
|
||||||
fieldWrapper.mappingType = (Class<?>) actualTypeArgument;
|
fieldWrapper.mappingType = (Class<?>) actualTypeArgument;
|
||||||
}
|
}
|
||||||
|
}catch (ClassCastException e){
|
||||||
|
throw new UnsupportedOperationException(String.format("不支持使用[%s]作为集合类型。请使用MutableList",fieldType.getName()));
|
||||||
|
}
|
||||||
} else if (Map.class.isAssignableFrom(fieldType)) {
|
} else if (Map.class.isAssignableFrom(fieldType)) {
|
||||||
Type genericType = field.getGenericType();
|
Type genericType = field.getGenericType();
|
||||||
if (genericType instanceof ParameterizedType) {
|
if (genericType instanceof ParameterizedType) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user