当目标类型为抽象时,如何处理来自ModelMapper的映射方法?

时间:2019-09-10 20:30:49

标签: java modelmapper

我正在尝试创建一个通用方法来接收实体并返回DTO。 为了实现这一目标,我创建了一个抽象的DTO类,所有DTO具体类都对此进行了扩展。

我做了类似的事情:

public class Foo extends Bean {
     ....
}

public class FooDTO extends BeanDTO {
     ....
}

public abstract class Controller<B extends Bean,
 D extends BeanDTO, F extends Facade<B, ?, ?>>


protected List<D> converter(List<B> beanList) throws Exception {
        Type listType = new TypeToken<List<D>>() {
        }.getType();
        List<D> dtoList = modelMapper.map(beanList, listType);
        return dtoList;
    }

但是当我尝试转换我的实体时,我得到了错误

  

无法实例化目标BeanDTO的实例。确保BeanDTO具有非私有的无参数构造函数。

我尝试使用以下提供程序: http://modelmapper.org/user-manual/property-mapping/#providers 但我不知道如何处理

Type listType = new TypeToken<List<D>>() {
        }.getType();

像例子一样。

0 个答案:

没有答案