mybatis-flex / mybatis-flex

mybatis-flex is an elegant Mybatis Enhancement Framework

Home Page:https://mybatis-flex.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请问 codegen 怎么设置为 List<String>

ft20082 opened this issue · comments

commented

生成代码是

ColumnConfig imageList = new ColumnConfig();
imageList.setColumnName("image_list");
imageList.setPropertyType("java.util.List<String>");
imageList.setTypeHandler(GsonTypeHandler.class);
globalConfig.setColumnConfig(imageList);

这样会导致一个问题,就是 import 不会识别把 <String> 去掉,所以生成的文件是错的
请问,应该怎么配置?

是不是优化为

imageList.setPropertyType("java.util.List<java.lang.String>");

在处理 import 时,把泛型里的类型根据条件来判断是否需要单独 import 一次,这样,也能支持其他类型的泛型

我查看 GsonTypeHandler 发现

public class GsonTypeHandler extends BaseJsonTypeHandler<Object> {

    private static Gson gson;
    private final Class<?> propertyType;
    private Class<?> genericType;

    public GsonTypeHandler(Class<?> propertyType) {
        this.propertyType = propertyType;
    }

    public GsonTypeHandler(Class<?> propertyType, Class<?> genericType) {
        this.propertyType = propertyType;
        this.genericType = genericType;
    }
}

propertyType 应该是集合的类型, genericType 应该集合里的泛型类型,请问这个怎么在 Column 里配置?

下个版本(v1.8.1)已支持 imageList.setPropertyType("java.util.List<String>"); 的配置,代码已提交,等 release。