我正在尝试将记录列表转换为某个Java对象(因此,ActiveJDBC Model转换为另一个Java类),但我希望能够为我的所有模型调用相同的方法并传递Model类型,类似于:
private <M extends Model, T> List<T> getObjects(Class<M> modelType, Class<T> objectType) {
List<T> records = new ArrayList<T>();
M.findWith(new ModelListener<M>() {
public void onModel(M row) {
// Here I would convert the Model to my desired object and add it to the list of records
}
}, null);
return records.isEmpty() ? null : records;
}
我会称之为:
getObjects(MyModel.class, MyObject.class);
我得到了
Exception: failed to determine Model class name, are you sure models have been instrumented?
on M.findWith(...)
知道如何让它发挥作用吗?
谢谢!